reset body cursor on request copy as it breaks transmission #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ?