Skip to content

Commit d6c78b7

Browse files
authored
Always close request body even if the proxy server had a custom response returned in filterRequest (#744)
1 parent c2d45c6 commit d6c78b7

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

https.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
322322
req = req.WithContext(requestContext)
323323
defer finishRequest()
324324

325+
// explicitly discard request body to avoid data races in certain RoundTripper implementations
326+
// see https://github.com/golang/go/issues/61596#issuecomment-1652345131
327+
defer req.Body.Close()
328+
325329
// Bug fix which goproxy fails to provide request
326330
// information URL in the context when does HTTPS MITM
327331
ctx.Req = req
@@ -364,12 +368,7 @@ func (proxy *ProxyHttpServer) handleHttps(w http.ResponseWriter, r *http.Request
364368
if !proxy.KeepHeader {
365369
RemoveProxyHeaders(ctx, req)
366370
}
367-
resp, err = func() (*http.Response, error) {
368-
// explicitly discard request body to avoid data races in certain RoundTripper implementations
369-
// see https://github.com/golang/go/issues/61596#issuecomment-1652345131
370-
defer req.Body.Close()
371-
return ctx.RoundTrip(req)
372-
}()
371+
resp, err = ctx.RoundTrip(req)
373372
if err != nil {
374373
ctx.Warnf("Cannot read TLS response from mitm'd server %v", err)
375374
return false

0 commit comments

Comments
 (0)