You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
seanmonstar opened this issue
Jun 6, 2018
· 0 comments
Labels
A-bodyArea: body streaming.C-featureCategory: feature. This is adding a new feature.E-easyEffort: easy. A task that would be a great starting point for a new contributor.
For instance, if a server receives the follow request:
POST /foo HTTP/1.1
content-length: 15
The Body in the Request should know these things, neither of which are currently true:
Body::content_length() should be Some(15).
Body::is_end_stream() should return true after poll_data has returned chunks of length totaling 15 bytes.
Steps to fixing
Adding an Option<u64> to the Kind::Chan variant of Body.
Changing h1::Conn::read_head to return an Option<BodyLength> instead of bool.
Updating the h1::Dispatcher to use the Option<BodyLength> to optionally set the new Option<u64> field of the Chan variant.
Updating Body::content_length to return the new field from Kind::Chan.
Updating Body::poll_data in the Kind::Chan variant to subtract from the new field the length of each chunk that passes by.
Updating Body::is_end_stream in the Kind::Chan variant to return true ifthe field is exactlySome(0)`.
Testing it works
Add a test to tests/client.rs with a server replying with the bytes HTTP/1.1 200 OK\r\ncontent-length: 5\r\n\r\nhello.
In the test, make a GET request to the server, and wait for the Response<Body>.
Add an assert_eq!(res.body().content_length(), Some(5)).
Add an assert!(!res.body().is_end_stream()) (the body should be done yet, there's still 5 bytes to stream).
Call res.body_mut().poll_data() to get the chunk. Assert it is 5 bytes for sanity.
Finally, assert!(res.body().is_end_stream()), as the 5 bytes have now been streamed.
The text was updated successfully, but these errors were encountered:
seanmonstar
added
E-easy
Effort: easy. A task that would be a great starting point for a new contributor.
C-feature
Category: feature. This is adding a new feature.
A-body
Area: body streaming.
labels
Jun 6, 2018
When getting a `Body` from hyper, such as in a client response,
the method `Body::content_length()` now returns a value if the header
was present.
Closes#1545
A-bodyArea: body streaming.C-featureCategory: feature. This is adding a new feature.E-easyEffort: easy. A task that would be a great starting point for a new contributor.
For instance, if a server receives the follow request:
The
Body
in theRequest
should know these things, neither of which are currently true:Body::content_length()
should beSome(15)
.Body::is_end_stream()
should return true afterpoll_data
has returned chunks of length totaling 15 bytes.Steps to fixing
Option<u64>
to theKind::Chan
variant ofBody
.h1::Conn::read_head
to return anOption<BodyLength>
instead ofbool
.h1::Dispatcher
to use theOption<BodyLength>
to optionally set the newOption<u64>
field of theChan
variant.Body::content_length
to return the new field fromKind::Chan
.Body::poll_data
in theKind::Chan
variant to subtract from the new field the length of each chunk that passes by.Body::is_end_stream
in theKind::Chan
variant to return true ifthe field is exactly
Some(0)`.Testing it works
tests/client.rs
with a server replying with the bytesHTTP/1.1 200 OK\r\ncontent-length: 5\r\n\r\nhello
.GET
request to the server, and wait for theResponse<Body>
.assert_eq!(res.body().content_length(), Some(5))
.assert!(!res.body().is_end_stream())
(the body should be done yet, there's still 5 bytes to stream).res.body_mut().poll_data()
to get the chunk. Assert it is 5 bytes for sanity.assert!(res.body().is_end_stream())
, as the 5 bytes have now been streamed.The text was updated successfully, but these errors were encountered: