1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-22 01:06:30 -05:00

refactor trojan WriteHeader function.

This commit is contained in:
Shelikhoo 2023-05-24 00:10:44 +01:00
parent 72475c2924
commit 680d5bb2ac
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -37,7 +37,7 @@ type ConnWriter struct {
// Write implements io.Writer // Write implements io.Writer
func (c *ConnWriter) Write(p []byte) (n int, err error) { func (c *ConnWriter) Write(p []byte) (n int, err error) {
if !c.headerSent { 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) 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 { 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() buffer := buf.StackNew()
defer buffer.Release() defer buffer.Release()