Skip to content

Commit 42aff87

Browse files
authored
refactor(http2): add decriptive error for non-empty body in CONNECT request (hyperium#3886)
Closes hyperium#3858
1 parent efa0b26 commit 42aff87

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/error.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ pub(super) enum User {
131131
feature = "ffi"
132132
))]
133133
BodyWriteAborted,
134+
/// User tried to send a connect request with a nonzero body
135+
#[cfg(all(feature = "client", feature = "http2"))]
136+
InvalidConnectWithBody,
134137
/// Error from future of user's Service.
135138
#[cfg(any(
136139
all(any(feature = "client", feature = "server"), feature = "http1"),
@@ -395,6 +398,11 @@ impl Error {
395398
Error::new_user(User::Body).with(cause)
396399
}
397400

401+
#[cfg(all(feature = "client", feature = "http2"))]
402+
pub(super) fn new_user_invalid_connect() -> Error {
403+
Error::new_user(User::InvalidConnectWithBody)
404+
}
405+
398406
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
399407
pub(super) fn new_shutdown(cause: std::io::Error) -> Error {
400408
Error::new(Kind::Shutdown).with(cause)
@@ -492,6 +500,10 @@ impl Error {
492500
feature = "ffi"
493501
))]
494502
Kind::User(User::BodyWriteAborted) => "user body write aborted",
503+
#[cfg(all(feature = "client", feature = "http2"))]
504+
Kind::User(User::InvalidConnectWithBody) => {
505+
"user sent CONNECT request with non-zero body"
506+
}
495507
#[cfg(any(
496508
all(any(feature = "client", feature = "server"), feature = "http1"),
497509
all(feature = "server", feature = "http2")

src/proto/h2/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,9 @@ where
673673
&& headers::content_length_parse_all(req.headers())
674674
.map_or(false, |len| len != 0)
675675
{
676-
warn!("h2 connect request with non-zero body not supported");
676+
debug!("h2 connect request with non-zero body not supported");
677677
cb.send(Err(TrySendError {
678-
error: crate::Error::new_h2(h2::Reason::INTERNAL_ERROR.into()),
678+
error: crate::Error::new_user_invalid_connect(),
679679
message: None,
680680
}));
681681
continue;

0 commit comments

Comments
 (0)