Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set TLS SNI hostname to be the same as Host field in header #428

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions client.go
Expand Up @@ -193,6 +193,9 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
}
}

hostPort, hostNoPort := hostPortNoPort(u)
sniHostName := hostNoPort

// Set the request headers using the capitalization for names and values in
// RFC examples. Although the capitalization shouldn't matter, there are
// servers that depend on it. The Header.Set method is not used because the
Expand All @@ -209,6 +212,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
case k == "Host":
if len(vs) > 0 {
req.Host = vs[0]
sniHostName = vs[0]
}
case k == "Upgrade" ||
k == "Connection" ||
Expand Down Expand Up @@ -282,7 +286,6 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
}
}

hostPort, hostNoPort := hostPortNoPort(u)
trace := httptrace.ContextClientTrace(ctx)
if trace != nil && trace.GetConn != nil {
trace.GetConn(hostPort)
Expand All @@ -307,7 +310,7 @@ func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader h
if u.Scheme == "https" {
cfg := cloneTLSConfig(d.TLSClientConfig)
if cfg.ServerName == "" {
cfg.ServerName = hostNoPort
cfg.ServerName = sniHostName
}
tlsConn := tls.Client(netConn, cfg)
netConn = tlsConn
Expand Down