Skip to content

Commit

Permalink
fix: send PROTOCOL_ERROR instead of REFUSED_STREAM for oversized head…
Browse files Browse the repository at this point in the history
…ers (#792)
  • Loading branch information
seanmonstar authored Aug 6, 2024
1 parent 7dbb5c5 commit e1693a7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/proto/streams/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,16 +719,16 @@ impl Recv {
// > that it cannot process.
//
// So, if peer is a server, we'll send a 431. In either case,
// an error is recorded, which will send a REFUSED_STREAM,
// an error is recorded, which will send a PROTOCOL_ERROR,
// since we don't want any of the data frames either.
tracing::debug!(
"stream error REFUSED_STREAM -- recv_push_promise: \
"stream error PROTOCOL_ERROR -- recv_push_promise: \
headers frame is over size; promised_id={:?};",
frame.promised_id(),
);
return Err(Error::library_reset(
frame.promised_id(),
Reason::REFUSED_STREAM,
Reason::PROTOCOL_ERROR,
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/proto/streams/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,15 @@ impl Inner {

actions.send.schedule_implicit_reset(
stream,
Reason::REFUSED_STREAM,
Reason::PROTOCOL_ERROR,
counts,
&mut actions.task);

actions.recv.enqueue_reset_expiration(stream, counts);

Ok(())
} else {
Err(Error::library_reset(stream.id, Reason::REFUSED_STREAM))
Err(Error::library_reset(stream.id, Reason::PROTOCOL_ERROR))
}
},
Err(RecvHeaderBlockError::State(err)) => Err(err),
Expand Down
6 changes: 3 additions & 3 deletions tests/h2-tests/tests/client_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ async fn recv_too_big_headers() {
srv.send_frame(frames::headers(3).response(200)).await;
// no reset for 1, since it's closed anyway
// but reset for 3, since server hasn't closed stream
srv.recv_frame(frames::reset(3).refused()).await;
srv.recv_frame(frames::reset(3).protocol_error()).await;
idle_ms(10).await;
};

Expand All @@ -865,7 +865,7 @@ async fn recv_too_big_headers() {
// waiting for a response.
let req1 = tokio::spawn(async move {
let err = req1.expect("send_request").0.await.expect_err("response1");
assert_eq!(err.reason(), Some(Reason::REFUSED_STREAM));
assert_eq!(err.reason(), Some(Reason::PROTOCOL_ERROR));
});

let request = Request::builder()
Expand All @@ -876,7 +876,7 @@ async fn recv_too_big_headers() {
let req2 = client.send_request(request, true);
let req2 = tokio::spawn(async move {
let err = req2.expect("send_request").0.await.expect_err("response2");
assert_eq!(err.reason(), Some(Reason::REFUSED_STREAM));
assert_eq!(err.reason(), Some(Reason::PROTOCOL_ERROR));
});

let conn = tokio::spawn(async move {
Expand Down
4 changes: 2 additions & 2 deletions tests/h2-tests/tests/push_promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ async fn recv_push_promise_over_max_header_list_size() {
frames::push_promise(1, 2).request("GET", "https://http2.akamai.com/style.css"),
)
.await;
srv.recv_frame(frames::reset(2).refused()).await;
srv.recv_frame(frames::reset(2).protocol_error()).await;
srv.send_frame(frames::headers(1).response(200).eos()).await;
idle_ms(10).await;
};
Expand All @@ -272,7 +272,7 @@ async fn recv_push_promise_over_max_header_list_size() {
.0
.await
.expect_err("response");
assert_eq!(err.reason(), Some(Reason::REFUSED_STREAM));
assert_eq!(err.reason(), Some(Reason::PROTOCOL_ERROR));
};

conn.drive(req).await;
Expand Down
2 changes: 1 addition & 1 deletion tests/h2-tests/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ async fn too_big_headers_sends_reset_after_431_if_not_eos() {
client
.recv_frame(frames::headers(1).response(431).eos())
.await;
client.recv_frame(frames::reset(1).refused()).await;
client.recv_frame(frames::reset(1).protocol_error()).await;
};

let srv = async move {
Expand Down

0 comments on commit e1693a7

Please sign in to comment.