From dd4c53d949d0b74a751473bbcf49aef3d744feae Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Mon, 5 Aug 2024 10:16:38 -0400 Subject: [PATCH] fix: send PROTOCOL_ERROR instead of REFUSED_STREAM for oversized headers --- src/proto/streams/recv.rs | 6 +++--- src/proto/streams/streams.rs | 4 ++-- tests/h2-tests/tests/client_request.rs | 6 +++--- tests/h2-tests/tests/push_promise.rs | 4 ++-- tests/h2-tests/tests/server.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/proto/streams/recv.rs b/src/proto/streams/recv.rs index 46cb87cd..f74098e8 100644 --- a/src/proto/streams/recv.rs +++ b/src/proto/streams/recv.rs @@ -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, )); } diff --git a/src/proto/streams/streams.rs b/src/proto/streams/streams.rs index e6c9ed8a..d3ef1188 100644 --- a/src/proto/streams/streams.rs +++ b/src/proto/streams/streams.rs @@ -504,7 +504,7 @@ impl Inner { actions.send.schedule_implicit_reset( stream, - Reason::REFUSED_STREAM, + Reason::PROTOCOL_ERROR, counts, &mut actions.task); @@ -512,7 +512,7 @@ impl Inner { 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), diff --git a/tests/h2-tests/tests/client_request.rs b/tests/h2-tests/tests/client_request.rs index 50be06e6..261fe65f 100644 --- a/tests/h2-tests/tests/client_request.rs +++ b/tests/h2-tests/tests/client_request.rs @@ -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; }; @@ -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() @@ -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 { diff --git a/tests/h2-tests/tests/push_promise.rs b/tests/h2-tests/tests/push_promise.rs index 94c1154e..6e2ab2a1 100644 --- a/tests/h2-tests/tests/push_promise.rs +++ b/tests/h2-tests/tests/push_promise.rs @@ -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; }; @@ -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; diff --git a/tests/h2-tests/tests/server.rs b/tests/h2-tests/tests/server.rs index 7155b586..2075d22b 100644 --- a/tests/h2-tests/tests/server.rs +++ b/tests/h2-tests/tests/server.rs @@ -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 {