fix host parsing

This commit is contained in:
ginuerzh
2024-07-10 22:57:49 +08:00
parent f2e32080e4
commit 4a4c64cc66
11 changed files with 76 additions and 56 deletions

View File

@ -13,6 +13,7 @@ import (
"net"
"net/http"
"net/http/httputil"
"strings"
"time"
"github.com/go-gost/core/bypass"
@ -105,7 +106,7 @@ func (h *sniHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, raddr net
host := req.Host
if _, _, err := net.SplitHostPort(host); err != nil {
host = net.JoinHostPort(host, "80")
host = net.JoinHostPort(strings.Trim(host, "[]"), "80")
}
log = log.WithFields(map[string]any{
"host": host,
@ -171,7 +172,7 @@ func (h *sniHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, raddr ne
}
if _, _, err := net.SplitHostPort(host); err != nil {
host = net.JoinHostPort(host, "443")
host = net.JoinHostPort(strings.Trim(host, "[]"), "443")
}
log = log.WithFields(map[string]any{