Skip to content

Commit

Permalink
Restore request body after reading in sign method
Browse files Browse the repository at this point in the history
Fixes awslabs#225

The problem is the the `sign` method in ProxyClient reads the `req.Body` and that results
in a closed reader.

When the request is actually send to the transport later, the body cannot be read and results
in a body length of 0 which does not match the passed req.ContentLength.

We tried to write tests for this, but the tests are not fully matching the real world because:
* they use io.NopCloser
* they use a HTTP mock client that doesn't actually read the body to send to the proxy (makes sense,
its a mock, but it's different than the actual implementation)
  • Loading branch information
ruudk committed Nov 8, 2024
1 parent 3cdd35b commit 22545e0
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions handler/proxy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (p *ProxyClient) sign(req *http.Request, service *endpoints.ResolvedEndpoin
}

body = bytes.NewReader(b)
req.Body = io.NopCloser(bytes.NewReader(b))
}

// S3 service should not have any escaping applied.
Expand Down

0 comments on commit 22545e0

Please sign in to comment.