From 7427a55ef1e67e4941a007ed1f5daa83a05e36d7 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Fri, 8 Jan 2021 12:00:46 +0000 Subject: [PATCH] Adjust Trojan Outbound postRequest --- proxy/trojan/client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/proxy/trojan/client.go b/proxy/trojan/client.go index f3122fea..272c2f04 100644 --- a/proxy/trojan/client.go +++ b/proxy/trojan/client.go @@ -7,6 +7,7 @@ import ( "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/platform" "github.com/xtls/xray-core/common/protocol" @@ -145,12 +146,13 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter postRequest := func() error { defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly) - var bodyWriter buf.Writer bufferWriter := buf.NewBufferedWriter(buf.NewWriter(conn)) + connWriter.Writer = bufferWriter connWriter.Target = destination connWriter.Account = account + var bodyWriter buf.Writer if destination.Network == net.Network_UDP { bodyWriter = &PacketWriter{Writer: connWriter, Target: destination} } else { @@ -167,6 +169,11 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter return newError("failed to flush payload").Base(err).AtWarning() } + // Send header if not sent yet + if _, err = connWriter.Write([]byte{}); err != nil { + return err.(*errors.Error).AtWarning() + } + if err = buf.Copy(link.Reader, bodyWriter, buf.UpdateActivity(timer)); err != nil { return newError("failed to transfer request payload").Base(err).AtInfo() }