Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/async_impl/h3_client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,14 @@ pub(crate) fn domain_as_uri((scheme, auth): Key) -> Uri {
.expect("domain is valid Uri")
}

/// Indicates the remote requested the peer to stop sending data without error.
/// Indicates the remote requested the peer to stop sending data without an HTTP/3 error.
///
/// Transport implementations such as quinn send `STOP_SENDING` with code `0` when
/// dropping an unread receive stream rather than `H3_NO_ERROR` (`0x100`).
fn is_stop_sending(e: &h3::error::StreamError) -> bool {
matches!(
e,
h3::error::StreamError::RemoteTerminate {
code: h3::error::Code::H3_NO_ERROR,
..
}
h3::error::StreamError::RemoteTerminate { code, .. }
if *code == h3::error::Code::H3_NO_ERROR || *code == 0
)
}
89 changes: 89 additions & 0 deletions tests/http3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,95 @@ async fn http3_test_h3_stop_sending_before_response_no_error() {
assert!(res.chunk().await.expect("read response eof").is_none());
}

#[cfg(feature = "http3")]
#[tokio::test]
async fn http3_test_h3_stop_sending_before_response_zero_code_request_body() {
let (response_tx, response_rx) = tokio::sync::mpsc::unbounded_channel::<bytes::Bytes>();
let response_rx = std::sync::Arc::new(std::sync::Mutex::new(Some(response_rx)));
let server_response_rx = response_rx.clone();

let server = server::Http3::new().build_with_stop_sending_before_response(
move |_| {
let server_response_rx = server_response_rx.clone();
async move {
let response_rx = server_response_rx.lock().unwrap().take().unwrap();
let response_stream =
futures_util::stream::unfold(response_rx, |mut rx| async move {
rx.recv().await.map(|chunk| {
(
Ok::<_, std::convert::Infallible>(hyper::body::Frame::data(chunk)),
rx,
)
})
});
let response_body =
reqwest::Body::wrap(http_body_util::StreamBody::new(response_stream));
http::Response::new(response_body)
}
},
h3::error::Code::from(0),
);

let (request_tx, request_rx) = tokio::sync::mpsc::unbounded_channel::<bytes::Bytes>();
let request_stream = futures_util::stream::unfold(request_rx, |mut rx| async move {
rx.recv().await.map(|chunk| {
(
Ok::<_, std::convert::Infallible>(hyper::body::Frame::data(chunk)),
rx,
)
})
});
let request_body = reqwest::Body::wrap(http_body_util::StreamBody::new(request_stream));

let url = format!("https://{}/", server.addr());
let client = reqwest::Client::builder()
.http3_prior_knowledge()
.danger_accept_invalid_certs(true)
.build()
.expect("client builder");

let mut res = client
.post(&url)
.version(http::Version::HTTP_3)
.body(request_body)
.send()
.await
.expect("response");

assert_eq!(res.version(), http::Version::HTTP_3);
assert_eq!(res.status(), reqwest::StatusCode::OK);

response_tx
.send(bytes::Bytes::from_static(b"first"))
.unwrap();
let first = res
.chunk()
.await
.ok()
.flatten()
.expect("missing first response chunk");
assert_eq!(first, bytes::Bytes::from_static(b"first"));

request_tx
.send(bytes::Bytes::from_static(b"late request chunk"))
.unwrap();
drop(request_tx);

response_tx
.send(bytes::Bytes::from_static(b"second"))
.unwrap();
drop(response_tx);

let second = res
.chunk()
.await
.ok()
.flatten()
.expect("missing second response chunk");
assert_eq!(second, bytes::Bytes::from_static(b"second"));
assert!(res.chunk().await.expect("read response eof").is_none());
}

#[cfg(feature = "http3")]
#[tokio::test]
async fn http3_test_h3_stop_sending_before_response_no_error_request_body() {
Expand Down