mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 08:31:30 +00:00
Cleanup vmesshttp
This commit is contained in:
parent
78a26fc139
commit
f841459004
|
@ -74,13 +74,13 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
|
||||||
|
|
||||||
func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
|
func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
|
||||||
if !c.http2 {
|
if !c.http2 {
|
||||||
return c.dialHTTP()
|
return c.dialHTTP(ctx)
|
||||||
} else {
|
} else {
|
||||||
return c.dialHTTP2()
|
return c.dialHTTP2(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) dialHTTP() (net.Conn, error) {
|
func (c *Client) dialHTTP(ctx context.Context) (net.Conn, error) {
|
||||||
conn, err := c.dialer.DialContext(c.ctx, N.NetworkTCP, c.serverAddr)
|
conn, err := c.dialer.DialContext(c.ctx, N.NetworkTCP, c.serverAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -92,6 +92,7 @@ func (c *Client) dialHTTP() (net.Conn, error) {
|
||||||
Proto: "HTTP/1.1",
|
Proto: "HTTP/1.1",
|
||||||
Header: c.headers.Clone(),
|
Header: c.headers.Clone(),
|
||||||
}
|
}
|
||||||
|
request = request.WithContext(ctx)
|
||||||
switch hostLen := len(c.host); hostLen {
|
switch hostLen := len(c.host); hostLen {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -114,7 +115,7 @@ func (c *Client) dialHTTP() (net.Conn, error) {
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) dialHTTP2() (net.Conn, error) {
|
func (c *Client) dialHTTP2(ctx context.Context) (net.Conn, error) {
|
||||||
pipeInReader, pipeInWriter := io.Pipe()
|
pipeInReader, pipeInWriter := io.Pipe()
|
||||||
request := &http.Request{
|
request := &http.Request{
|
||||||
Method: c.method,
|
Method: c.method,
|
||||||
|
@ -124,6 +125,7 @@ func (c *Client) dialHTTP2() (net.Conn, error) {
|
||||||
Proto: "HTTP/2",
|
Proto: "HTTP/2",
|
||||||
Header: c.headers.Clone(),
|
Header: c.headers.Clone(),
|
||||||
}
|
}
|
||||||
|
request = request.WithContext(ctx)
|
||||||
switch hostLen := len(c.host); hostLen {
|
switch hostLen := len(c.host); hostLen {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
@ -90,9 +90,8 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
if f, ok := writer.(http.Flusher); ok {
|
writer.(http.Flusher).Flush()
|
||||||
f.Flush()
|
|
||||||
}
|
|
||||||
var metadata M.Metadata
|
var metadata M.Metadata
|
||||||
metadata.Source = sHttp.SourceAddress(request)
|
metadata.Source = sHttp.SourceAddress(request)
|
||||||
if h, ok := writer.(http.Hijacker); ok {
|
if h, ok := writer.(http.Hijacker); ok {
|
||||||
|
|
Loading…
Reference in a new issue