Closed
Description
When sending a streaming request (using Body::channel
) without content-length, the request terminates when dropping the Sender
. But when a content-length is set, dropping the Sender
before all bytes are sent will result in a request being stuck.
use hyper::{self, Body};
#[tokio::main]
async fn main() {
let (tx, body) = Body::channel();
let req = hyper::Request::builder()
.uri("http://httpbin.org/post")
.method(hyper::Method::POST)
.header("content-length", 1337)
.body(body)
.unwrap();
let client = hyper::Client::new();
std::mem::drop(tx);
println!("Sending request...");
let res = client.request(req).await.unwrap();
println!("Response: {:?}", res);
}
The example above will terminate when the content-length header is removed, but like this it hangs until the server closes the connection.
On the other hand, when explicitly aborting the sender using tx.abort()
, the request will terminate with an error.