Skip to content

Commit

Permalink
https: use host header for TLS SNI if not set explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
isobit committed Jul 22, 2024
1 parent a9d614d commit 8b3692a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internal/schemes/http/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func Connect(cfg ndog.ConnectConfig) error {
body = cfg.Stream.Reader
}

tlsConfig, err := cfg.TLS.Config(false, nil)
if err != nil {
return err
}

// Convert to HTTP request
httpReq, err := http.NewRequest(opts.Method, reqUrl.String(), body)
if err != nil {
Expand All @@ -111,15 +116,15 @@ func Connect(cfg ndog.ConnectConfig) error {
if strings.EqualFold(key, "host") {
log.Logf(2, "setting host: %s", val)
httpReq.Host = val

if tlsConfig.ServerName == "" && httpReq.URL.Scheme == "https" {
log.Logf(1, "TLS server name not explicitly set, using host header value")
tlsConfig.ServerName = val
}
}
httpReq.Header.Add(key, val)
}

tlsConfig, err := cfg.TLS.Config(false, nil)
if err != nil {
return err
}

transport := &http.Transport{
TLSClientConfig: tlsConfig,
}
Expand Down

0 comments on commit 8b3692a

Please sign in to comment.