From 680d5bb2acdd1564e62cb175736368d0cf4cc155 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Wed, 24 May 2023 00:10:44 +0100 Subject: [PATCH] refactor trojan WriteHeader function. --- proxy/trojan/protocol.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/proxy/trojan/protocol.go b/proxy/trojan/protocol.go index dd20e7248..962f5db73 100644 --- a/proxy/trojan/protocol.go +++ b/proxy/trojan/protocol.go @@ -37,7 +37,7 @@ type ConnWriter struct { // Write implements io.Writer func (c *ConnWriter) Write(p []byte) (n int, err error) { if !c.headerSent { - if err := c.WriteHeader(); err != nil { + if err := c.writeHeader(); err != nil { return 0, newError("failed to write request header").Base(err) } } @@ -61,6 +61,15 @@ func (c *ConnWriter) WriteMultiBuffer(mb buf.MultiBuffer) error { } func (c *ConnWriter) WriteHeader() error { + if !c.headerSent { + if err := c.writeHeader(); err != nil { + return err + } + } + return nil +} + +func (c *ConnWriter) writeHeader() error { buffer := buf.StackNew() defer buffer.Release()