Skip to content

Commit

Permalink
martian: set CONNECT content length before response modifiers
Browse files Browse the repository at this point in the history
Modify CONNECT response content length before it gets logged.
  • Loading branch information
Choraden committed May 21, 2024
1 parent bcc2f82 commit deee6ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/martian/proxy_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ func (p *proxyConn) handleConnectRequest(req *http.Request) error {
return p.writeErrorResponse(req, cerr)
}

res.ContentLength = -1

if err := p.modifyResponse(res); err != nil {
log.Debugf(ctx, "error modifying CONNECT response: %v", err)
return p.writeErrorResponse(req, err)
Expand All @@ -250,8 +252,6 @@ func (p *proxyConn) handleConnectRequest(req *http.Request) error {
return p.writeResponse(res)
}

res.ContentLength = -1

if err := p.tunnel("CONNECT", res, crw); err != nil {
log.Errorf(ctx, "CONNECT tunnel: %v", err)
}
Expand Down
3 changes: 3 additions & 0 deletions internal/martian/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,9 @@ func TestIntegrationConnect(t *testing.T) { //nolint:tparallel // Subtests share
if got, want := res.StatusCode, 200; got != want {
t.Fatalf("res.StatusCode: got %d, want %d", got, want)
}
if res.ContentLength != -1 {
t.Fatalf("res.ContentLength: got %d, want -1", res.ContentLength)
}

if !tm.RequestModified() {
t.Error("tm.RequestModified(): got false, want true")
Expand Down

0 comments on commit deee6ea

Please sign in to comment.