-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
retry with request body and redirection #10
Closed
openmohan
wants to merge
2
commits into
PuerkitoBio:master
from
openmohan:fix-request-body-when-redirect
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. It works with the test because the body is not consumed in the redirects (only in the retries), but the Go documentation for the
GetBody
field mentions:Returning
req.Body
would not allow reading the body more than once. I think it should do similar to what is done on line 363 below when a retry is needed, reset thebytes.Reader
to the beginning and create a new nop closer:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mna In the
(m *mockRoundTripper) RoundTrip
we are consuming the body.I think the issue itself is invalid.
http.Client
level. Therehttp
does not have to follow a redirect.GetBody
, although by default go provides support to common readersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@openmohan
You mean #9, i.e. there's nothing to fix in
rehttp
regardingGetBody
? If so I think you may be right. The reason the other Go package had to make changes regarding this was because AIUI it creates a new request, butrehttp
does not create new requests, it uses the one provided by the caller. As you mention, it is the caller's responsibility to setGetBody
, and for retriesrehttp
already handles that part.And actually setting the
GetBody
field inrehttp
would possibly overwrite whatever the caller did set, which would be wrong.I'll link to this discussion in the issue #9 in case the person that created the issue has more input for this, but otherwise I think I'll just close it (and the PR) in a while if I don't hear back from them. Let me know if I misunderstood what you meant, though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is correct @mna :)