proxy: Unify timeouts of different protocols for reading the first payload

This commit is contained in:
lrh2000
2022-06-25 19:34:32 +01:00
committed by Shelikhoo
parent 17d85263e2
commit 396ee770b7
6 changed files with 16 additions and 13 deletions
+3 -3
View File
@@ -8,7 +8,6 @@ import (
"net/http"
"net/url"
"sync"
"time"
"golang.org/x/net/http2"
@@ -23,6 +22,7 @@ import (
"github.com/v2fly/v2ray-core/v5/common/signal"
"github.com/v2fly/v2ray-core/v5/common/task"
"github.com/v2fly/v2ray-core/v5/features/policy"
"github.com/v2fly/v2ray-core/v5/proxy"
"github.com/v2fly/v2ray-core/v5/transport"
"github.com/v2fly/v2ray-core/v5/transport/internet"
"github.com/v2fly/v2ray-core/v5/transport/internet/tls"
@@ -83,11 +83,11 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
var firstPayload []byte
if reader, ok := link.Reader.(buf.TimeoutReader); ok {
// 0-RTT optimization for HTTP/2: If the payload comes within 50 ms, it can be
// 0-RTT optimization for HTTP/2: If the payload comes very soon, it can be
// transmitted together. Note we should not get stuck here, as the payload may
// not exist (considering to access MySQL database via a HTTP proxy, where the
// server sends hello to the client first).
if mbuf, _ := reader.ReadMultiBufferTimeout(50 * time.Millisecond); mbuf != nil {
if mbuf, _ := reader.ReadMultiBufferTimeout(proxy.FirstPayloadTimeout); mbuf != nil {
mlen := mbuf.Len()
firstPayload = bytespool.Alloc(mlen)
mbuf, _ = buf.SplitBytes(mbuf, firstPayload)