httpsig icon indicating copy to clipboard operation
httpsig copied to clipboard

reset body cursor on request copy as it breaks transmission

Open poolpOrg opened this issue 2 years ago • 0 comments

NewSignTransport() begins by cloning a request so it works on a copy of the original request but when reading the body into a bytes buffer, the cursor from both requests moves forward (I didn't get a chance to deep dive into this but it behaves like it's cloning a pointer to a region that's resized, proven by writing experimental code that shows the body is consumed on both requests regardless of which one is being read).

This causes an issue whenever trying to sign a request containing a body as the Content-Length header will present the original body size, but after the b.ReadFrom() call the remaining body size to read will be 0, causing a mismatch and a panic:

http: ContentLength=36 with Body length 0

A quick fix is to use the io.NopCloser() on the request clone too, making sure both requests are reset.

PS: do we really need to clone the request ?

poolpOrg avatar May 10 '23 13:05 poolpOrg