feat(http/body-eos): introduce BodyWithEosFn<B, F>
#4246
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.
this commit introduces a piece of
http_body::Body
middleware.BodyWithEosFn<B, F>
wraps an innerB
-typed body, and invokes anF
-typed callback when the end of the stream is reached.detecting the end of a request body or response body stream is a tricky, reoccuring problem in different pieces of our
tower
middleware. streams can end with aNone
, aSome(Ok(_))
trailers frame, aSome(Err(_))
error, can be dropped prior to completion, or aSome(Ok(_))
data frame that leaves the body reporting atrue
hint fromBody::is_end_stream()
.this is very easy to do incorrectly.
this piece of body middleware abstracts over all of these state transitions, and allows callers to instead provide a callback that will be invoked when the stream finishes.
Signed-off-by: katelyn martin [email protected]