Compare commits

...

2 Commits

Author SHA1 Message Date
好为 7785671495
Merge 873ca6009f into 9ec25ca502 2024-06-13 00:38:13 +00:00
willard 873ca6009f Update the Host field in the request header
This update checks for the 'Host' value in the request header, specifically assigning it to 'u.Host' if no value is found. This same logic is applied to 'cfg.ServerName'. The aim of this change is to ensure a correct 'Host' value is used throughout, addressing a bug related to setting the 'Host' field of the header.
2023-10-09 02:54:12 +08:00
1 changed files with 10 additions and 2 deletions

View File

@ -187,6 +187,10 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
return nil, nil, errMalformedURL
}
host := requestHeader.Get("Host")
if host == "" {
host = u.Host
}
req := &http.Request{
Method: http.MethodGet,
URL: u,
@ -194,7 +198,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
ProtoMajor: 1,
ProtoMinor: 1,
Header: make(http.Header),
Host: u.Host,
Host: host,
}
req = req.WithContext(ctx)
@ -340,8 +344,12 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
cfg := cloneTLSConfig(d.TLSClientConfig)
if cfg.ServerName == "" {
if host != "" {
cfg.ServerName = host
} else {
cfg.ServerName = hostNoPort
}
}
tlsConn := tls.Client(netConn, cfg)
netConn = tlsConn