Skip to content

Commit

Permalink
martian: fix connection hangs in mitm mode
Browse files Browse the repository at this point in the history
A regression was introduced in 9cc9854 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"
  • Loading branch information
mmatczuk committed Feb 23, 2024
1 parent d47e35c commit 445a896
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/martian/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ func (p *Proxy) init() {
p.initOnce.Do(func() {
if p.RoundTripper == nil {
p.rt = &http.Transport{
// TODO(adamtanner): This forces the http.Transport to not upgrade requests
// to HTTP/2 in Go 1.6+. Remove this once Martian can support HTTP/2.
TLSNextProto: make(map[string]func(string, *tls.Conn) http.RoundTripper),
Proxy: http.ProxyFromEnvironment,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: time.Second,
Expand All @@ -143,7 +140,9 @@ func (p *Proxy) init() {
}

if t, ok := p.rt.(*http.Transport); ok {
t = t.Clone()
// TODO(adamtanner): This forces the http.Transport to not upgrade requests
// to HTTP/2 in Go 1.6+. Remove this once Martian can support HTTP/2.
t.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper)

if p.DialContext == nil {
p.DialContext = t.DialContext
Expand Down

0 comments on commit 445a896

Please sign in to comment.