mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-02 03:57:38 +03:00
fix: never overwrite the port
This commit is contained in:
parent
f014c00546
commit
55c3a064cc
2 changed files with 10 additions and 14 deletions
|
@ -112,21 +112,17 @@ 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 != "" {
|
||||
// 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)
|
||||
// req.Host can be host:port, in which case we need to extract the host part
|
||||
host, _, err := net.SplitHostPort(req.Host)
|
||||
if err != nil {
|
||||
// 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
|
||||
// No port, just use the whole string
|
||||
host = req.Host
|
||||
}
|
||||
_, port, err := net.SplitHostPort(*reqAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
*reqAddr = net.JoinHostPort(host, port)
|
||||
}
|
||||
return tr.Buffer(), nil
|
||||
} else if h.isTLS(pre) {
|
||||
|
|
|
@ -80,7 +80,7 @@ func TestSnifferTCP(t *testing.T) {
|
|||
putback, err = sniffer.TCP(stream, &reqAddr)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, *buf, putback)
|
||||
assert.Equal(t, "example.com:8080", reqAddr)
|
||||
assert.Equal(t, "example.com:10086", reqAddr)
|
||||
|
||||
// Test TLS
|
||||
*buf, err = base64.StdEncoding.DecodeString("FgMBARcBAAETAwPJL2jlt1OAo+Rslkjv/aqKiTthKMaCKg2Gvd+uALDbDCDdY+UIk8ouadEB9fC3j52Y1i7SJZqGIgBRIS6kKieYrAAoEwITAcAswCvAMMAvwCTAI8AowCfACsAJwBTAEwCdAJwAPQA8ADUALwEAAKIAAAAOAAwAAAlpcGluZm8uaW8ABQAFAQAAAAAAKwAJCAMEAwMDAgMBAA0AGgAYCAQIBQgGBAEFAQIBBAMFAwIDAgIGAQYDACMAAAAKAAgABgAdABcAGAAQAAsACQhodHRwLzEuMQAzACYAJAAdACBguQbqNJNyamYxYcrBFpBP7pWv5TgZsP9gwGtMYNKVBQAxAAAAFwAA/wEAAQAALQACAQE=")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue