mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-03 02:08:45 +00:00
XHTTP transport: Some optimizations (#5803)
https://github.com/XTLS/Xray-core/pull/5801 https://github.com/XTLS/Xray-core/pull/5808 --------- Co-authored-by: Sergei Ozeranskii <sergey.ozeranskiy@gmail.com> Co-authored-by: rufsieus <rufsieus@gmail.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/signal/done"
|
||||
@@ -23,7 +24,7 @@ type DialerClient interface {
|
||||
OpenStream(context.Context, string, string, io.Reader, bool) (io.ReadCloser, net.Addr, net.Addr, error)
|
||||
|
||||
// ctx, url, sessionId, seqStr, body, contentLength
|
||||
PostPacket(context.Context, string, string, string, io.Reader, int64) error
|
||||
PostPacket(context.Context, string, string, string, buf.MultiBuffer) error
|
||||
}
|
||||
|
||||
// implements splithttp.DialerClient in terms of direct network connections
|
||||
@@ -89,14 +90,13 @@ func (c *DefaultDialerClient) OpenStream(ctx context.Context, url string, sessio
|
||||
return
|
||||
}
|
||||
|
||||
func (c *DefaultDialerClient) PostPacket(ctx context.Context, url string, sessionId string, seqStr string, body io.Reader, contentLength int64) error {
|
||||
func (c *DefaultDialerClient) PostPacket(ctx context.Context, url string, sessionId string, seqStr string, payload buf.MultiBuffer) error {
|
||||
method := c.transportConfig.GetNormalizedUplinkHTTPMethod()
|
||||
req, err := http.NewRequestWithContext(context.WithoutCancel(ctx), method, url, body)
|
||||
req, err := http.NewRequestWithContext(context.WithoutCancel(ctx), method, url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.ContentLength = contentLength
|
||||
c.transportConfig.FillPacketRequest(req, sessionId, seqStr)
|
||||
c.transportConfig.FillPacketRequest(req, sessionId, seqStr, payload)
|
||||
|
||||
if c.httpVersion != "1.1" {
|
||||
resp, err := c.client.Do(req)
|
||||
@@ -117,6 +117,7 @@ func (c *DefaultDialerClient) PostPacket(ctx context.Context, url string, sessio
|
||||
// times, the body is already drained after the first
|
||||
// request
|
||||
requestBuff := new(bytes.Buffer)
|
||||
requestBuff.Grow(512 + int(req.ContentLength))
|
||||
common.Must(req.Write(requestBuff))
|
||||
|
||||
var uploadConn any
|
||||
|
||||
Reference in New Issue
Block a user