diff --git a/extras/sniff/sniff.go b/extras/sniff/sniff.go index e0c94d4..b2d7419 100644 --- a/extras/sniff/sniff.go +++ b/extras/sniff/sniff.go @@ -112,11 +112,21 @@ func (h *Sniffer) TCP(stream quic.Stream, reqAddr *string) ([]byte, error) { tr := &teeReader{Stream: stream, Pre: pre} req, _ := http.ReadRequest(bufio.NewReader(tr)) if req != nil && req.Host != "" { - _, port, err := net.SplitHostPort(*reqAddr) + // req.Host may already contain the port. + // If it does, just overwrite the whole address with req.Host. + // Otherwise, use the port in reqAddr. + _, _, err := net.SplitHostPort(req.Host) if err != nil { - return nil, err + // Not host:port format, append the port from reqAddr + _, port, err := net.SplitHostPort(*reqAddr) + if err != nil { + return nil, err + } + *reqAddr = net.JoinHostPort(req.Host, port) + } else { + // Already host:port format + *reqAddr = req.Host } - *reqAddr = net.JoinHostPort(req.Host, port) } return tr.Buffer(), nil } else if h.isTLS(pre) {