-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce getters so a request's body can be read multiple times
In #646, I attempted to fix a problem whereby when using HTTP/2 we were sending invalid requests during automatic retries because a `Request` struct with a body cannot be reused in the context of HTTP/2. Unfortunately, it wasn't blowing up quite as spectacularly as before, the fix didn't quite work either. It would set a new `Body` before retries, but that body would be pointing to an `io.Reader` that was already exhausted as it had been fully consumed during the original request, thereby producing an empty request body. Here we modify the `Do` and `CallMultipart` interfaces so that they take body buffers instead of just readers. When making a request, we create a new reader for those buffers every time, thus ensuring a fresh one. This is relatively trivial when making non-multipart requests (which is most requests) because we were already producing a buffer in almost the right place. It's a little more complicated for multipart requests (file uploads) because we had encoding scheme that wasn't quite compatible, but I've done some refactoring there (and added more tests) to bring things in line. We also add a much improved test framework this time around that verifies that the problem is fixed and will definitively stay fixed. Fixes #647.
- Loading branch information
Showing
6 changed files
with
182 additions
and
53 deletions.
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
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
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
Oops, something went wrong.