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

Get content-length for Incoming HTTP2 Bodies #1557

Merged
merged 4 commits into from
Jun 18, 2018
Merged

Get content-length for Incoming HTTP2 Bodies #1557

merged 4 commits into from
Jun 18, 2018

Conversation

joshleeb
Copy link

@joshleeb joshleeb commented Jun 9, 2018

Update Body::content_length to return the content length of when Body::Kind is H2, instead of returning None. Kind::H2 also holds the value of the content-length header as well as the h2::RecvStream.

Closes: #1546

src/body/body.rs Outdated
@@ -39,7 +39,7 @@ enum Kind {
abort_rx: oneshot::Receiver<()>,
rx: mpsc::Receiver<Result<Chunk, ::Error>>,
},
H2(h2::RecvStream),
H2(h2::RecvStream, Option<u64>),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-pick: maybe swap these and make it a struct-like variant (H2 { ... })

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.

Looking good!

There were a couple tests added in #1556 with lines commented out waiting for this change, want to uncomment them in this PR so we have tests for this functionality?

src/body/body.rs Outdated
})
}
Kind::H2 {
content_length: ref mut _len,
Copy link
Member

Choose a reason for hiding this comment

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

Since it's not needed, this pattern could be replace with just ...

@lnicola
Copy link
Contributor

lnicola commented Jun 10, 2018

@joshleeb if you get a chance, can you include a commit to enable the corresponding checks in the tests from #1556?

@@ -110,6 +111,7 @@ where
if let Some(len) = body.content_length() {
headers::set_content_length_if_missing(req.headers_mut(), len);
}
let content_length = content_length_parse_all(req.headers());
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it sets content_length of the Response's body by parsing the length from the Request. (Curious the tests didn't catch it...)

Copy link
Author

@joshleeb joshleeb Jun 12, 2018

Choose a reason for hiding this comment

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

It looks like it does pick it up but I suspect that because the panic is not in the main test thread it doesn't cause the test to fail.

https://travis-ci.org/hyperium/hyper/jobs/390534326#L825
https://travis-ci.org/hyperium/hyper/jobs/390534326#L825

@seanmonstar
Copy link
Member

Sorry, it seems github doesn't send notifications about rebased/ammended commits. I'll look now.

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, looks great!

Seems merging the upgrade PR made this have merge conflicts, but I suspect that aren't too bad. It's probably just around the poll_eof method, mostly because this PR reformats it (I'd personally recommend not reformating unrelated changes because of the risk of conflicts :D).

Josh Leeb-du Toit added 4 commits June 15, 2018 16:51
Add `Body::Kind::H2` to contain the content length of the body.

Closes: #1546
Update `Body::content_length` to return the content length if
`Body::Kind` is `H2`, instead of returning `None`.
Refactor the `Kind::H2` enum variant to be a named variant, rather than
an unnamed variant. This is to make fields, currently `recv:
h2::RecvStream`, and `content_length: Option<u64>` more readable.
@joshleeb
Copy link
Author

Ahh damn sorry about that. Should be all fixed now 👍

@seanmonstar seanmonstar merged commit 9a28268 into hyperium:master Jun 18, 2018
@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.

3 participants