Skip to content

Commit

Permalink
fix: ipv6 http host addr
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Feb 21, 2024
1 parent 6399347 commit 9e7eaf7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions listener/http/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"net"
"net/http"
"net/netip"
"strings"
)

Expand Down Expand Up @@ -48,6 +49,11 @@ func removeExtraHTTPHostPort(req *http.Request) {

if pHost, port, err := net.SplitHostPort(host); err == nil && (port == "80" || port == "443") {
host = pHost
if ip, err := netip.ParseAddr(pHost); err == nil && ip.Is6() {
// RFC 2617 Sec 3.2.2, for IPv6 literal
// addresses the Host header needs to follow the RFC 2732 grammar for "host"
host = "[" + host + "]"
}
}

req.Host = host
Expand Down

0 comments on commit 9e7eaf7

Please sign in to comment.