Skip to content
Merged
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
6 changes: 5 additions & 1 deletion src/proto/streams/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ impl Stream {
Some(val) => *rem = val,
None => return Err(()),
},
ContentLength::Head => return Err(()),
ContentLength::Head => {
if len != 0 {
return Err(());
}
}
_ => {}
}

Expand Down
44 changes: 44 additions & 0 deletions tests/h2-tests/tests/client_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,50 @@ async fn malformed_response_headers_dont_unlink_stream() {
join(srv, client).await;
}

#[tokio::test]
async fn allow_empty_data_for_head() {
h2_support::trace_init!();
let (io, mut srv) = mock::new();

let srv = async move {
let settings = srv.assert_client_handshake().await;
assert_default_settings!(settings);
srv.recv_frame(
frames::headers(1)
.request("HEAD", "https://example.com/")
.eos(),
)
.await;
srv.send_frame(
frames::headers(1)
.response(200)
.field("content-length", 100),
)
.await;
srv.send_frame(frames::data(1, "").eos()).await;
};

let h2 = async move {
let (mut client, h2) = client::Builder::new()
.handshake::<_, Bytes>(io)
.await
.unwrap();
tokio::spawn(async {
h2.await.expect("connection failed");
});
let request = Request::builder()
.method(Method::HEAD)
.uri("https://example.com/")
.body(())
.unwrap();
let (response, _) = client.send_request(request, true).unwrap();
let (_, mut body) = response.await.unwrap().into_parts();
assert_eq!(body.data().await.unwrap().unwrap(), "");
};

join(srv, h2).await;
}

const SETTINGS: &'static [u8] = &[0, 0, 0, 4, 0, 0, 0, 0, 0];
const SETTINGS_ACK: &'static [u8] = &[0, 0, 0, 4, 1, 0, 0, 0, 0];

Expand Down