Skip to content

Conversation

@cratelyn
Copy link
Member

@cratelyn cratelyn commented Oct 7, 2025

the http_body::Body::is_end_stream() trait method is provided, by
default, such that it always returns false.

- https://docs.rs/http-body/latest/src/http_body/lib.rs.html#58-60

pub trait Body {
    // ...

    /// Returns `true` when the end of stream has been reached.
    ///
    /// An end of stream means that `poll_frame` will return `None`.
    ///
    /// A return value of `false` **does not** guarantee that a value will be
    /// returned from `poll_frame`.
    fn is_end_stream(&self) -> bool {
        false
    }

    // ...
}

we have a MockBody type that allows unit tests to exercise how body
middleware to particular sequences of poll_frame() outcomes. today,
the MockBody type reports the is_end_stream() hint when there are no
more poll values to yield.

this commit introduces a new method, MockBody::without_eos(), which
will instruct the mock body to always return false from
is_end_stream().

this allows test cases to exercise end-of-stream cases in which an inner
Body does not provide a more accurate hint than the provided default.

Signed-off-by: katelyn martin [email protected]

the `http_body::Body::is_end_stream()` trait method is provided, by
default, such that it always returns `false`.

\- <https://docs.rs/http-body/latest/src/http_body/lib.rs.html#58-60>

```rust
pub trait Body {
    // ...

    /// Returns `true` when the end of stream has been reached.
    ///
    /// An end of stream means that `poll_frame` will return `None`.
    ///
    /// A return value of `false` **does not** guarantee that a value will be
    /// returned from `poll_frame`.
    fn is_end_stream(&self) -> bool {
        false
    }

    // ...
}
```

we have a `MockBody` type that allows unit tests to exercise how body
middleware to particular sequences of `poll_frame()` outcomes. today,
the `MockBody` type reports the `is_end_stream()` hint when there are no
more poll values to yield.

this commit introduces a new method, `MockBody::without_eos()`, which
will instruct the mock body to always return `false` from
`is_end_stream()`.

this allows test cases to exercise end-of-stream cases in which an inner
`Body` does not provide a more accurate hint than the provided default.

Signed-off-by: katelyn martin <[email protected]>
@cratelyn cratelyn requested a review from a team as a code owner October 7, 2025 16:25
@cratelyn cratelyn self-assigned this Oct 7, 2025
@cratelyn cratelyn merged commit f598cf0 into main Oct 8, 2025
15 checks passed
@cratelyn cratelyn deleted the kate/mock-http-body.allow-disabling-is-end-stream branch October 8, 2025 14:57
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.

3 participants