Fix http proxy server

This commit is contained in:
世界 2022-07-14 18:20:52 +08:00
parent 029ab1ce4f
commit 51de48ed21
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -45,21 +45,6 @@ func HandleConnection(ctx context.Context, conn net.Conn, reader *std_bufio.Read
}
}
var requestConn net.Conn
if reader.Buffered() > 0 {
_buffer := buf.StackNewSize(reader.Buffered())
defer common.KeepAlive(_buffer)
buffer := common.Dup(_buffer)
defer buffer.Release()
_, err = buffer.ReadFullFrom(reader, reader.Buffered())
if err != nil {
return err
}
requestConn = bufio.NewCachedConn(conn, buffer)
} else {
requestConn = conn
}
if request.Method == "CONNECT" {
portStr := request.URL.Port()
if portStr == "" {
@ -72,6 +57,21 @@ func HandleConnection(ctx context.Context, conn net.Conn, reader *std_bufio.Read
}
metadata.Protocol = "http"
metadata.Destination = destination
var requestConn net.Conn
if reader.Buffered() > 0 {
_buffer := buf.StackNewSize(reader.Buffered())
defer common.KeepAlive(_buffer)
buffer := common.Dup(_buffer)
defer buffer.Release()
_, err = buffer.ReadFullFrom(reader, reader.Buffered())
if err != nil {
return err
}
requestConn = bufio.NewCachedConn(conn, buffer)
} else {
requestConn = conn
}
return handler.NewConnection(ctx, requestConn, metadata)
}