#[derive(Debug)] pub(super) enum Kind {
Parse(Parse),
User(User), /// A message reached EOF, but is not complete. #[allow(unused)]
IncompleteMessage, /// A connection received a message (or bytes) when not waiting for one. #[cfg(feature = "http1")]
UnexpectedMessage, /// A pending item was dropped before ever being processed.
Canceled, /// Indicates a channel (client or body sender) is closed.
ChannelClosed, /// An `io::Error` that occurred while trying to read or write to a network stream. #[cfg(any(feature = "http1", feature = "http2"))]
Io, /// Error occurred while connecting. #[allow(unused)]
Connect, /// Error creating a TcpListener. #[cfg(all(feature = "tcp", feature = "server"))]
Listen, /// Error accepting on an Incoming stream. #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "server")]
Accept, /// User took too long to send headers #[cfg(all(feature = "http1", feature = "server", feature = "runtime"))]
HeaderTimeout, /// Error while reading a body from connection. #[cfg(any(feature = "http1", feature = "http2", feature = "stream"))]
Body, /// Error while writing a body to connection. #[cfg(any(feature = "http1", feature = "http2"))]
BodyWrite, /// Error calling AsyncWrite::shutdown() #[cfg(feature = "http1")]
Shutdown,
/// A general error from h2. #[cfg(feature = "http2")]
Http2,
}
#[derive(Debug)] pub(super) enum User { /// Error calling user's HttpBody::poll_data(). #[cfg(any(feature = "http1", feature = "http2"))]
Body, /// The user aborted writing of the outgoing body.
BodyWriteAborted, /// Error calling user's MakeService. #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "server")]
MakeService, /// Error from future of user's Service. #[cfg(any(feature = "http1", feature = "http2"))]
Service, /// User tried to send a certain header in an unexpected context. /// /// For example, sending both `content-length` and `transfer-encoding`. #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "server")]
UnexpectedHeader, /// User tried to create a Request with bad version. #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "client")]
UnsupportedVersion, /// User tried to create a CONNECT Request with the Client. #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "client")]
UnsupportedRequestMethod, /// User tried to respond with a 1xx (not 101) response code. #[cfg(feature = "http1")] #[cfg(feature = "server")]
UnsupportedStatusCode, /// User tried to send a Request with Client with non-absolute URI. #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "client")]
AbsoluteUriRequired,
/// User tried polling for an upgrade that doesn't exist.
NoUpgrade,
/// User polled for an upgrade, but low-level API is not using upgrades. #[cfg(feature = "http1")]
ManualUpgrade,
/// User called `server::Connection::without_shutdown()` on an HTTP/2 conn. #[cfg(feature = "server")]
WithoutShutdownNonHttp1,
/// The dispatch task is gone. #[cfg(feature = "client")]
DispatchGone,
/// User aborted in an FFI callback. #[cfg(feature = "ffi")]
AbortedByCallback,
}
// Sentinel type to indicate the error was caused by a timeout. #[derive(Debug)] pub(super) struct TimedOut;
impl Error { /// Returns true if this was an HTTP parse error. pubfn is_parse(&self) -> bool {
matches!(self.inner.kind, Kind::Parse(_))
}
/// Returns true if this was an HTTP parse error caused by a message that was too large. pubfn is_parse_too_large(&self) -> bool {
matches!( self.inner.kind,
Kind::Parse(Parse::TooLarge) | Kind::Parse(Parse::UriTooLong)
)
}
/// Returns true if this was an HTTP parse error caused by an invalid response status code or /// reason phrase. pubfn is_parse_status(&self) -> bool {
matches!(self.inner.kind, Kind::Parse(Parse::Status))
}
/// Returns true if this error was caused by user code. pubfn is_user(&self) -> bool {
matches!(self.inner.kind, Kind::User(_))
}
/// Returns true if this was about a `Request` that was canceled. pubfn is_canceled(&self) -> bool {
matches!(self.inner.kind, Kind::Canceled)
}
/// Returns true if a sender's channel is closed. pubfn is_closed(&self) -> bool {
matches!(self.inner.kind, Kind::ChannelClosed)
}
/// Returns true if this was an error from `Connect`. pubfn is_connect(&self) -> bool {
matches!(self.inner.kind, Kind::Connect)
}
/// Returns true if the connection closed before a message could complete. pubfn is_incomplete_message(&self) -> bool {
matches!(self.inner.kind, Kind::IncompleteMessage)
}
/// Returns true if the body write was aborted. pubfn is_body_write_aborted(&self) -> bool {
matches!(self.inner.kind, Kind::User(User::BodyWriteAborted))
}
/// Returns true if the error was caused by a timeout. pubfn is_timeout(&self) -> bool { self.find_source::<TimedOut>().is_some()
}
/// Consumes the error, returning its cause. pubfn into_cause(self) -> Option<Box<dyn StdError + Send + Sync>> { self.inner.cause
}
#[cfg(feature = "http2")] pub(super) fn h2_reason(&self) -> h2::Reason { // Find an h2::Reason somewhere in the cause stack, if it exists, // otherwise assume an INTERNAL_ERROR. self.find_source::<h2::Error>()
.and_then(|h2_err| h2_err.reason())
.unwrap_or(h2::Reason::INTERNAL_ERROR)
}
#[cfg(feature = "http2")] #[test] fn h2_reason_nested() { let recvd = Error::new_h2(h2::Error::from(h2::Reason::HTTP_1_1_REQUIRED)); // Suppose a user were proxying the received error let svc_err = Error::new_user_service(recvd);
assert_eq!(svc_err.h2_reason(), h2::Reason::HTTP_1_1_REQUIRED);
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.25 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.