From 24f90c1ce34ca8ef35fdc856f3e8c11a8205061e Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Tue, 12 Apr 2022 19:29:37 +0800 Subject: [PATCH] fix tcp redirect when sniffing tls --- handler/redirect/tcp/handler.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/handler/redirect/tcp/handler.go b/handler/redirect/tcp/handler.go index 55285c2..a8ebaa6 100644 --- a/handler/redirect/tcp/handler.go +++ b/handler/redirect/tcp/handler.go @@ -210,11 +210,13 @@ func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, rad if host == "" { host = dstAddr.String() } else { - _, port, _ := net.SplitHostPort(dstAddr.String()) - if port == "" { - port = "443" + if _, _, err := net.SplitHostPort(host); err != nil { + _, port, _ := net.SplitHostPort(dstAddr.String()) + if port == "" { + port = "443" + } + host = net.JoinHostPort(host, port) } - host = net.JoinHostPort(host, port) } log = log.WithFields(map[string]any{