Skip to content

Conversation

cratelyn
Copy link
Member

@cratelyn cratelyn commented Oct 17, 2025

this commit introduces a piece of http_body::Body middleware.

BodyWithEosFn<B, F> wraps an inner B-typed body, and invokes an F-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 a None, a Some(Ok(_)) trailers frame, a Some(Err(_)) error, can be dropped prior to completion, or a Some(Ok(_)) data frame that leaves the body reporting a true hint from Body::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]

@cratelyn cratelyn self-assigned this Oct 17, 2025
@cratelyn cratelyn marked this pull request as ready for review October 17, 2025 15:19
@cratelyn cratelyn requested a review from a team as a code owner October 17, 2025 15:19
this commit introduces a piece of `http_body::Body` middleware.

`BodyWithEosFn<B, F>` wraps an inner `B`-typed body, and invokes an
`F`-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 a `None`, a `Some(Ok(_))` trailers frame, a
`Some(Err(_))` error, can be dropped prior to completion, or a
`Some(Ok(_))` data frame that leaves the body reporting a `true` hint
from `Body::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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant