Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Body know about incoming Content-Length #1554

Merged
merged 1 commit into from
Jun 8, 2018

Conversation

lnicola
Copy link
Contributor

@lnicola lnicola commented Jun 8, 2018

Fixes #1545.

I'm not sure about:

  • what to do if the incoming body is longer than the content-length; is it ok to abort? I think Firefox does that
  • the test (code and location)

@lnicola lnicola force-pushed the incoming-body-len branch 2 times, most recently from 2d69173 to 6f755b5 Compare June 8, 2018 04:10
@lnicola lnicola changed the title [WIP] Make Body know about incoming Content-Length Make Body know about incoming Content-Length Jun 8, 2018
Copy link
Member

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks for jumping on this! Just some minor thoughts left inline.

src/body/body.rs Outdated
///
/// Useful when wanting to stream chunks from another thread.
#[inline]
pub fn channel_with_length(content_length: u64) -> (Sender, Body) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I'd suggest making this just pub(crate).

Oh and then, these 2 functions can probably be reduced to calling a 3rd, private constructor, fn new_channel(content_length: Option<u64>), to remove duplicate code, yea?

src/body/body.rs Outdated
Async::Ready(Some(Ok(chunk))) => Ok(Async::Ready(Some(chunk))),
Async::Ready(Some(Ok(chunk))) => {
if let Some(ref mut len) = *len {
match len.checked_sub(chunk.len() as u64) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the constructor to set a length on the channel variant is private, we can rely on hyper's decoder to always limit the body size that is streamed (it enforces the length from the connection). Just for sanity, we could keep a debug assertion. Something like:

if let Some(ref mut len) = *len {
    debug_assert!(*len >= chunk.len());
    *len = *len - chunk.len();
}

@lnicola lnicola force-pushed the incoming-body-len branch 2 times, most recently from e283968 to 2d885f7 Compare June 8, 2018 19:13
@lnicola lnicola force-pushed the incoming-body-len branch from 2d885f7 to b27ba1d Compare June 8, 2018 19:16
@lnicola
Copy link
Contributor Author

lnicola commented Jun 8, 2018

Done, I think.

@seanmonstar seanmonstar merged commit a0a0fcd into hyperium:master Jun 8, 2018
@lnicola lnicola deleted the incoming-body-len branch June 8, 2018 20:03
@seanmonstar
Copy link
Member

Thanks!

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.

2 participants