Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset body cursor on request copy as it breaks transmission #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

poolpOrg
Copy link

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 ?

httpsig.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants