fix(server): convert panic to error if Connection::without_shutdown called on HTTP/2 conn

This commit is contained in:
Sean McArthur
2021-09-15 15:26:01 -07:00
parent c88011da4e
commit ea3e228287
2 changed files with 18 additions and 5 deletions

View File

@@ -128,6 +128,10 @@ pub(super) enum User {
#[cfg(feature = "http1")]
ManualUpgrade,
/// User called `server::Connection::without_shutdown()` on an HTTP/2 conn.
#[cfg(feature = "server")]
WithoutShutdownNonHttp1,
/// User aborted in an FFI callback.
#[cfg(feature = "ffi")]
AbortedByCallback,
@@ -355,6 +359,11 @@ impl Error {
Error::new_user(User::Body).with(cause)
}
#[cfg(feature = "server")]
pub(super) fn new_without_shutdown_not_h1() -> Error {
Error::new(Kind::User(User::WithoutShutdownNonHttp1))
}
#[cfg(feature = "http1")]
pub(super) fn new_shutdown(cause: std::io::Error) -> Error {
Error::new(Kind::Shutdown).with(cause)
@@ -449,6 +458,10 @@ impl Error {
Kind::User(User::NoUpgrade) => "no upgrade available",
#[cfg(feature = "http1")]
Kind::User(User::ManualUpgrade) => "upgrade expected but low level API in use",
#[cfg(feature = "server")]
Kind::User(User::WithoutShutdownNonHttp1) => {
"without_shutdown() called on a non-HTTP/1 connection"
}
#[cfg(feature = "ffi")]
Kind::User(User::AbortedByCallback) => "operation aborted by an application callback",
}