Skip to content

Commit

Permalink
martian(proxy): don't close connection on connect response
Browse files Browse the repository at this point in the history
Fixes #813
  • Loading branch information
mmatczuk committed May 28, 2024
1 parent 7879269 commit 0227154
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/martian/proxy_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,19 @@ func (p *proxyConn) writeResponse(res *http.Response) error {
defer p.conn.SetWriteDeadline(time.Time{})
}

if req.Close || p.closing() {
if p.closing() {
res.Close = true
} else {
if req.Close {
res.Close = true
}
// Support CONNECT over HTTP/1.0.
// If connect is successful, the connection should not be closed.
if req.Method == http.MethodConnect && res.StatusCode/100 == 2 {
res.Close = false
}
}

if res.Close {
res.Header.Add("Connection", "close")
}
Expand Down

0 comments on commit 0227154

Please sign in to comment.