Open
Description
Currently, the 'String' is the only native data type that implements hyper::body::Body
.
If we're passing other data types as a body, we need to add the http_body_util
crate and add a little bit of boiler plate when building our request.
use http_body_util::Full;
let some_bytes = vec![0_u8, 1, 2];
let mut req = Request::builder()
.method("POST")
.body(Full::<Bytes>::from(some_bytes))
.unwrap();
Note: While the request builder itself may not require the body to implement the Body trait, both the sender and connection returned by http1::handshake
require the request's body to implement it.
With the body trait implemented for Vec<u8>
(just one example that probably should implement body) we could leave out the http_body_util
crate. Building a request would also become more intuitive and ergonomic.
let some_bytes = vec![0_u8, 1, 2];
let mut req = Request::builder()
.method("POST")
.body(some_bytes)
.unwrap();