Skip to content

Commit

Permalink
Allow responses of HEAD requests to have empty DATA frames (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
eaufavor authored Oct 22, 2020
1 parent cb2c7ac commit 0ba7d13
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
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

0 comments on commit 0ba7d13

Please sign in to comment.