Fix websocket client initialize

This commit is contained in:
世界 2023-12-22 20:37:49 +08:00
parent aeb7308e81
commit a0cab4f563
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -55,15 +55,10 @@ func NewClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, opt
if !strings.HasPrefix(requestURL.Path, "/") {
requestURL.Path = "/" + requestURL.Path
}
headers := make(http.Header)
for key, value := range options.Headers {
headers[key] = value
if key == "Host" {
if len(value) > 1 {
return nil, E.New("multiple Host headers")
}
requestURL.Host = value[0]
}
headers := options.Headers.Build()
if host := headers.Get("Host"); host != "" {
headers.Del("Host")
requestURL.Host = host
}
if headers.Get("User-Agent") == "" {
headers.Set("User-Agent", "Go-http-client/1.1")