This commit is contained in:
好为 2024-06-13 00:38:13 +00:00 committed by GitHub
commit 7785671495
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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 return nil, nil, errMalformedURL
} }
host := requestHeader.Get("Host")
if host == "" {
host = u.Host
}
req := &http.Request{ req := &http.Request{
Method: http.MethodGet, Method: http.MethodGet,
URL: u, URL: u,
@ -194,7 +198,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
ProtoMajor: 1, ProtoMajor: 1,
ProtoMinor: 1, ProtoMinor: 1,
Header: make(http.Header), Header: make(http.Header),
Host: u.Host, Host: host,
} }
req = req.WithContext(ctx) req = req.WithContext(ctx)
@ -340,7 +344,11 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
cfg := cloneTLSConfig(d.TLSClientConfig) cfg := cloneTLSConfig(d.TLSClientConfig)
if cfg.ServerName == "" { if cfg.ServerName == "" {
cfg.ServerName = hostNoPort if host != "" {
cfg.ServerName = host
} else {
cfg.ServerName = hostNoPort
}
} }
tlsConn := tls.Client(netConn, cfg) tlsConn := tls.Client(netConn, cfg)
netConn = tlsConn netConn = tlsConn