Skip to content

Commit

Permalink
Use iana H2 error code description
Browse files Browse the repository at this point in the history
The iana h2 error code descriptions
(https://www.iana.org/assignments/http2-parameters/http2-parameters.xhtml#error-code) seem to be more comprehensive and shorter.
  • Loading branch information
eaufavor committed Nov 30, 2021
1 parent ce81583 commit 162af4f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
36 changes: 18 additions & 18 deletions src/frame/reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,20 @@ impl Reason {
/// Get a string description of the error code.
pub fn description(&self) -> &str {
match self.0 {
0 => "not a result of an error",
1 => "unspecific protocol error detected",
2 => "unexpected internal error encountered",
3 => "flow-control protocol violated",
4 => "settings ACK not received in timely manner",
5 => "received frame when stream half-closed",
6 => "frame with invalid size",
7 => "refused stream before processing any application logic",
8 => "stream no longer needed",
9 => "unable to maintain the header compression context",
10 => {
"connection established in response to a CONNECT request was reset or abnormally \
closed"
}
11 => "detected excessive load generating behavior",
12 => "security properties do not meet minimum requirements",
13 => "endpoint requires HTTP/1.1",
0 => "graceful shutdown",
1 => "protocol error detected",
2 => "implementation fault",
3 => "flow-control limits exceeded",
4 => "settings not acknowledged",
5 => "frame received for closed stream",
6 => "frame size incorrect",
7 => "stream not processed",
8 => "stream cancelled",
9 => "compression state not updated",
10 => "TCP connection error for CONNECT method",
11 => "processing capacity exceeded",
12 => "negotiated TLS parameters not acceptable",
13 => "use HTTP/1.1 for the request",
_ => "unknown reason",
}
}
Expand Down Expand Up @@ -129,6 +126,9 @@ impl fmt::Debug for Hex {

impl fmt::Display for Reason {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.description())
match self.0 {
0..=13 => write!(fmt, "{}", self.description()),
_ => write!(fmt, "unknown error code {}", self.0),
}
}
}
4 changes: 2 additions & 2 deletions tests/h2-tests/tests/client_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ async fn send_reset_notifies_recv_stream() {
let err = body.next().await.unwrap().expect_err("RecvBody");
assert_eq!(
err.to_string(),
"stream error sent by user: refused stream before processing any application logic"
"stream error sent by user: stream not processed"
);
};

Expand Down Expand Up @@ -676,7 +676,7 @@ async fn sending_request_on_closed_connection() {
};

let poll_err = poll_fn(|cx| client.poll_ready(cx)).await.unwrap_err();
let msg = "connection error detected: unspecific protocol error detected";
let msg = "connection error detected: protocol error detected";
assert_eq!(poll_err.to_string(), msg);

let request = Request::builder()
Expand Down
2 changes: 1 addition & 1 deletion tests/h2-tests/tests/codec_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ async fn update_max_frame_len_at_rest() {
assert_eq!(codec.max_recv_frame_size(), 16_384);
assert_eq!(
codec.next().await.unwrap().unwrap_err().to_string(),
"frame with invalid size"
"frame size incorrect"
);

// drain codec buffer
Expand Down
8 changes: 4 additions & 4 deletions tests/h2-tests/tests/flow_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async fn recv_data_overflows_connection_window() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: flow-control protocol violated"
"connection error detected: flow-control limits exceeded"
);
};

Expand All @@ -227,7 +227,7 @@ async fn recv_data_overflows_connection_window() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: flow-control protocol violated"
"connection error detected: flow-control limits exceeded"
);
};
join(conn, req).await;
Expand Down Expand Up @@ -278,7 +278,7 @@ async fn recv_data_overflows_stream_window() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"stream error detected: flow-control protocol violated"
"stream error detected: flow-control limits exceeded"
);
};

Expand Down Expand Up @@ -358,7 +358,7 @@ async fn stream_error_release_connection_capacity() {
.expect_err("body");
assert_eq!(
err.to_string(),
"stream error detected: unspecific protocol error detected"
"stream error detected: protocol error detected"
);
cap.release_capacity(to_release).expect("release_capacity");
};
Expand Down
12 changes: 6 additions & 6 deletions tests/h2-tests/tests/push_promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async fn recv_push_when_push_disabled_is_conn_error() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: unspecific protocol error detected"
"connection error detected: protocol error detected"
);
};

Expand All @@ -174,7 +174,7 @@ async fn recv_push_when_push_disabled_is_conn_error() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: unspecific protocol error detected"
"connection error detected: protocol error detected"
);
};

Expand Down Expand Up @@ -388,7 +388,7 @@ async fn recv_push_promise_skipped_stream_id() {
.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: unspecific protocol error detected"
"connection error detected: protocol error detected"
);
};

Expand All @@ -398,7 +398,7 @@ async fn recv_push_promise_skipped_stream_id() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: unspecific protocol error detected"
"connection error detected: protocol error detected"
);
};

Expand Down Expand Up @@ -446,7 +446,7 @@ async fn recv_push_promise_dup_stream_id() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: unspecific protocol error detected"
"connection error detected: protocol error detected"
);
};

Expand All @@ -456,7 +456,7 @@ async fn recv_push_promise_dup_stream_id() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: unspecific protocol error detected"
"connection error detected: protocol error detected"
);
};

Expand Down
6 changes: 3 additions & 3 deletions tests/h2-tests/tests/stream_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async fn errors_if_recv_frame_exceeds_max_frame_size() {
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: frame with invalid size"
"connection error detected: frame size incorrect"
);
};

Expand All @@ -218,7 +218,7 @@ async fn errors_if_recv_frame_exceeds_max_frame_size() {
let err = h2.await.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: frame with invalid size"
"connection error detected: frame size incorrect"
);
};
join(conn, req).await;
Expand Down Expand Up @@ -329,7 +329,7 @@ async fn recv_goaway_finishes_processed_streams() {
let err = client.get("https://example.com/").await.unwrap_err();
assert_eq!(
err.to_string(),
"connection error received: not a result of an error"
"connection error received: graceful shutdown"
);
};

Expand Down

0 comments on commit 162af4f

Please sign in to comment.