Fix for hang on capture_body: error in starlette #1038
Merged
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.
What does this pull request do?
Because Starlette does not propagate the cached
request._body
properly, we've always had to use a hack in order to make sure we don't hang requests by streaming the body before the request does.This PR ensures that for any
capture_body
setting that's notoff
, we perform this hack in the pre-request stage so that everyone will have easy access to the body down the line.Before this fix, if
capture_body
was set toerror
, and an error was thrown after the body was already streamed, we would hang while trying to capture the body. I consider this a bug in Starlette but this should let us work around it.Related issues
Fixes #1032