mirror of https://github.com/v2ray/v2ray-core
improve http proxy effeciency
parent
b3ec97058e
commit
e3a00d1400
|
@ -21,9 +21,9 @@ func NewChanReader(stream <-chan *alloc.Buffer) *ChanReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ChanReader) fill() {
|
func (this *ChanReader) fill() {
|
||||||
b, ok := <-this.stream
|
b, open := <-this.stream
|
||||||
this.current = b
|
this.current = b
|
||||||
if !ok {
|
if !open {
|
||||||
this.eof = true
|
this.eof = true
|
||||||
this.current = nil
|
this.current = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,8 +108,8 @@ func (this *HttpProxyServer) handleConnection(conn *net.TCPConn) {
|
||||||
log.Info("Request to remote: %s", string(buffer.Value))
|
log.Info("Request to remote: %s", string(buffer.Value))
|
||||||
packet := v2net.NewPacket(v2net.NewTCPDestination(address), buffer, true)
|
packet := v2net.NewPacket(v2net.NewTCPDestination(address), buffer, true)
|
||||||
ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
|
ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
|
||||||
|
go func() {
|
||||||
defer close(ray.InboundInput())
|
defer close(ray.InboundInput())
|
||||||
|
|
||||||
responseReader := bufio.NewReader(NewChanReader(ray.InboundOutput()))
|
responseReader := bufio.NewReader(NewChanReader(ray.InboundOutput()))
|
||||||
response, err := http.ReadResponse(responseReader, request)
|
response, err := http.ReadResponse(responseReader, request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -117,9 +117,10 @@ func (this *HttpProxyServer) handleConnection(conn *net.TCPConn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
responseBuffer := alloc.NewBuffer().Clear()
|
responseBuffer := alloc.NewBuffer().Clear()
|
||||||
|
defer responseBuffer.Release()
|
||||||
response.Write(responseBuffer)
|
response.Write(responseBuffer)
|
||||||
conn.Write(responseBuffer.Value)
|
conn.Write(responseBuffer.Value)
|
||||||
responseBuffer.Release()
|
}()
|
||||||
} else {
|
} else {
|
||||||
response := &http.Response{
|
response := &http.Response{
|
||||||
Status: "400 Bad Request",
|
Status: "400 Bad Request",
|
||||||
|
@ -157,6 +158,7 @@ func (this *HttpProxyServer) handleConnect(request *http.Request, address v2net.
|
||||||
buffer := alloc.NewSmallBuffer().Clear()
|
buffer := alloc.NewSmallBuffer().Clear()
|
||||||
response.Write(buffer)
|
response.Write(buffer)
|
||||||
writer.Write(buffer.Value)
|
writer.Write(buffer.Value)
|
||||||
|
buffer.Release()
|
||||||
|
|
||||||
packet := v2net.NewPacket(v2net.NewTCPDestination(address), nil, true)
|
packet := v2net.NewPacket(v2net.NewTCPDestination(address), nil, true)
|
||||||
ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
|
ray := this.space.PacketDispatcher().DispatchToOutbound(packet)
|
||||||
|
|
Loading…
Reference in New Issue