Skip to content

Commit f989d89

Browse files
committed
Fix calculate host for HTTP connect client
1 parent 2b0a53a commit f989d89

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

protocol/http/client.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Client struct {
2323
serverAddr M.Socksaddr
2424
username string
2525
password string
26+
host string
2627
path string
2728
headers http.Header
2829
}
@@ -48,6 +49,12 @@ func NewClient(options Options) *Client {
4849
if options.Dialer == nil {
4950
client.dialer = N.SystemDialer
5051
}
52+
var host string
53+
if client.headers != nil {
54+
host = client.headers.Get("Host")
55+
client.headers.Del("Host")
56+
client.host = host
57+
}
5158
return client
5259
}
5360

@@ -71,16 +78,11 @@ func (c *Client) DialContext(ctx context.Context, network string, destination M.
7178
"Proxy-Connection": []string{"Keep-Alive"},
7279
},
7380
}
74-
var host string
75-
if c.headers != nil {
76-
host = c.headers.Get("Host")
77-
c.headers.Del("Host")
78-
}
79-
if host != "" && host != destination.Fqdn {
81+
if c.host != "" && c.host != destination.Fqdn {
8082
if c.path != "" {
8183
return nil, E.New("Host header and path are not allowed at the same time")
8284
}
83-
request.Host = host
85+
request.Host = c.host
8486
request.URL = &url.URL{Opaque: destination.String()}
8587
} else {
8688
request.URL = &url.URL{Host: destination.String()}

0 commit comments

Comments
 (0)