Skip to content

Commit

Permalink
fix client SNI handling (#3613)
Browse files Browse the repository at this point in the history
* fix: client sni handling

* chore: add comment
  • Loading branch information
tobyxdd committed Nov 7, 2022
1 parent 5fe9f9b commit 2de4af0
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"net"
"strings"

"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
Expand Down Expand Up @@ -232,13 +231,10 @@ func newClient(
tlsConf = tlsConf.Clone()
}
if tlsConf.ServerName == "" {
sni := host
if strings.IndexByte(sni, ':') != -1 {
var err error
sni, _, err = net.SplitHostPort(sni)
if err != nil {
return nil, err
}
sni, _, err := net.SplitHostPort(host)
if err != nil {
// It's ok if net.SplitHostPort returns an error - it could be a hostname/IP address without a port.
sni = host
}

tlsConf.ServerName = sni
Expand Down

0 comments on commit 2de4af0

Please sign in to comment.