mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-03 20:47: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}
|
tr := &teeReader{Stream: stream, Pre: pre}
|
||||||
req, _ := http.ReadRequest(bufio.NewReader(tr))
|
req, _ := http.ReadRequest(bufio.NewReader(tr))
|
||||||
if req != nil && req.Host != "" {
|
if req != nil && req.Host != "" {
|
||||||
// req.Host may already contain the port.
|
// req.Host can be host:port, in which case we need to extract the host part
|
||||||
// If it does, just overwrite the whole address with req.Host.
|
host, _, err := net.SplitHostPort(req.Host)
|
||||||
// Otherwise, use the port in reqAddr.
|
|
||||||
_, _, err := net.SplitHostPort(req.Host)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Not host:port format, append the port from reqAddr
|
// No port, just use the whole string
|
||||||
|
host = req.Host
|
||||||
|
}
|
||||||
_, port, err := net.SplitHostPort(*reqAddr)
|
_, port, err := net.SplitHostPort(*reqAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
*reqAddr = net.JoinHostPort(req.Host, port)
|
*reqAddr = net.JoinHostPort(host, port)
|
||||||
} else {
|
|
||||||
// Already host:port format
|
|
||||||
*reqAddr = req.Host
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return tr.Buffer(), nil
|
return tr.Buffer(), nil
|
||||||
} else if h.isTLS(pre) {
|
} else if h.isTLS(pre) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ func TestSnifferTCP(t *testing.T) {
|
||||||
putback, err = sniffer.TCP(stream, &reqAddr)
|
putback, err = sniffer.TCP(stream, &reqAddr)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, *buf, putback)
|
assert.Equal(t, *buf, putback)
|
||||||
assert.Equal(t, "example.com:8080", reqAddr)
|
assert.Equal(t, "example.com:10086", reqAddr)
|
||||||
|
|
||||||
// Test TLS
|
// Test TLS
|
||||||
*buf, err = base64.StdEncoding.DecodeString("FgMBARcBAAETAwPJL2jlt1OAo+Rslkjv/aqKiTthKMaCKg2Gvd+uALDbDCDdY+UIk8ouadEB9fC3j52Y1i7SJZqGIgBRIS6kKieYrAAoEwITAcAswCvAMMAvwCTAI8AowCfACsAJwBTAEwCdAJwAPQA8ADUALwEAAKIAAAAOAAwAAAlpcGluZm8uaW8ABQAFAQAAAAAAKwAJCAMEAwMDAgMBAA0AGgAYCAQIBQgGBAEFAQIBBAMFAwIDAgIGAQYDACMAAAAKAAgABgAdABcAGAAQAAsACQhodHRwLzEuMQAzACYAJAAdACBguQbqNJNyamYxYcrBFpBP7pWv5TgZsP9gwGtMYNKVBQAxAAAAFwAA/wEAAQAALQACAQE=")
|
*buf, err = base64.StdEncoding.DecodeString("FgMBARcBAAETAwPJL2jlt1OAo+Rslkjv/aqKiTthKMaCKg2Gvd+uALDbDCDdY+UIk8ouadEB9fC3j52Y1i7SJZqGIgBRIS6kKieYrAAoEwITAcAswCvAMMAvwCTAI8AowCfACsAJwBTAEwCdAJwAPQA8ADUALwEAAKIAAAAOAAwAAAlpcGluZm8uaW8ABQAFAQAAAAAAKwAJCAMEAwMDAgMBAA0AGgAYCAQIBQgGBAEFAQIBBAMFAwIDAgIGAQYDACMAAAAKAAgABgAdABcAGAAQAAsACQhodHRwLzEuMQAzACYAJAAdACBguQbqNJNyamYxYcrBFpBP7pWv5TgZsP9gwGtMYNKVBQAxAAAAFwAA/wEAAQAALQACAQE=")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue