mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
Reduce http proxy client overhead by 1RTT
This commit is contained in:
parent
e19749180e
commit
f0e63c6e3c
@ -3,9 +3,11 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"v2ray.com/core"
|
"v2ray.com/core"
|
||||||
@ -90,7 +92,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||||||
p = c.policyManager.ForLevel(user.Level)
|
p = c.policyManager.ForLevel(user.Level)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setUpHttpTunnel(conn, conn, &destination, user); err != nil {
|
if err := setUpHttpTunnel(conn, &destination, user); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +105,15 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||||||
}
|
}
|
||||||
responseFunc := func() error {
|
responseFunc := func() error {
|
||||||
defer timer.SetTimeout(p.Timeouts.UplinkOnly)
|
defer timer.SetTimeout(p.Timeouts.UplinkOnly)
|
||||||
return buf.Copy(buf.NewReader(conn), link.Writer, buf.UpdateActivity(timer))
|
bc := bufio.NewReader(conn)
|
||||||
|
resp, err := http.ReadResponse(bc, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return newError(resp.Status)
|
||||||
|
}
|
||||||
|
return buf.Copy(buf.NewReader(bc), link.Writer, buf.UpdateActivity(timer))
|
||||||
}
|
}
|
||||||
|
|
||||||
var responseDonePost = task.OnSuccess(responseFunc, task.Close(link.Writer))
|
var responseDonePost = task.OnSuccess(responseFunc, task.Close(link.Writer))
|
||||||
@ -115,7 +125,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setUpHttpTunnel will create a socket tunnel via HTTP CONNECT method
|
// setUpHttpTunnel will create a socket tunnel via HTTP CONNECT method
|
||||||
func setUpHttpTunnel(reader io.Reader, writer io.Writer, destination *net.Destination, user *protocol.MemoryUser) error {
|
func setUpHttpTunnel(writer io.Writer, destination *net.Destination, user *protocol.MemoryUser) error {
|
||||||
var headers []string
|
var headers []string
|
||||||
destNetAddr := destination.NetAddr()
|
destNetAddr := destination.NetAddr()
|
||||||
headers = append(headers, "CONNECT "+destNetAddr+" HTTP/1.1")
|
headers = append(headers, "CONNECT "+destNetAddr+" HTTP/1.1")
|
||||||
@ -133,11 +143,6 @@ func setUpHttpTunnel(reader io.Reader, writer io.Writer, destination *net.Destin
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Clear()
|
|
||||||
if _, err := b.ReadFrom(reader); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user