saucelabs / forwarder

Forwarder is a production-ready, fast MITM proxy with PAC support. It's suitable for debugging, intercepting and manipulating HTTP traffic. It's used as a core component of Sauce Labs Sauce Connect Proxy.
https://forwarder-proxy.io
Mozilla Public License 2.0
202 stars 13 forks source link

martian: fix connection hangs in mitm mode #718

Closed mmatczuk closed 4 months ago

mmatczuk commented 4 months ago

A regression was introduced in 9cc985423c4b49f98580ff7531ee671aa5f474da that allowed use of HTTP/2 inside MITM.

This patch adds the following to all http.Transport instances

t.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper)

Interestingly with that t = t.Clone() we get an error

forwarder encountered an unexpected error
net/http: HTTP/1.x transport connection broken: malformed HTTP response "\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x80\x00\x04\x00\x01\x00\x00\x00\x05\x00\xff\xff\xff\x00\x00\x04\b\x00\x00\x00\x00\x00\x7f\xff\x00\x00\x00\x00\b\a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"