parent
e6fee89726
commit
be0a8c325f
@ -0,0 +1,42 @@ |
|||||||
|
use std::fmt; |
||||||
|
|
||||||
|
/// Indicates the specific type/cause of a capacity error.
|
||||||
|
#[derive(PartialEq, Eq, Clone, Copy)] |
||||||
|
pub enum CapacityError { |
||||||
|
/// Too many headers provided (see [`httparse::Error::TooManyHeaders`]).
|
||||||
|
TooManyHeaders, |
||||||
|
/// Received header is too long.
|
||||||
|
HeaderTooLong, |
||||||
|
/// Message is bigger than the maximum allowed size.
|
||||||
|
MessageTooLong { |
||||||
|
/// The size of the message.
|
||||||
|
size: usize, |
||||||
|
/// The maximum allowed message size.
|
||||||
|
max_size: usize, |
||||||
|
}, |
||||||
|
/// TCP buffer is full.
|
||||||
|
TcpBufferFull, |
||||||
|
} |
||||||
|
|
||||||
|
impl fmt::Debug for CapacityError { |
||||||
|
#[inline] |
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||||
|
match *self { |
||||||
|
Self::TooManyHeaders => write!(f, "Too many headers"), |
||||||
|
Self::HeaderTooLong => write!(f, "Header too long"), |
||||||
|
Self::MessageTooLong { size, max_size } => { |
||||||
|
write!(f, "Message too long: {} > {}", size, max_size) |
||||||
|
} |
||||||
|
Self::TcpBufferFull => write!(f, "Incoming TCP buffer is full"), |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl fmt::Display for CapacityError { |
||||||
|
#[inline] |
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||||
|
fmt::Debug::fmt(self, f) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl std::error::Error for CapacityError {} |
@ -0,0 +1,113 @@ |
|||||||
|
use crate::protocol::frame::coding::Data; |
||||||
|
use std::fmt; |
||||||
|
|
||||||
|
/// Indicates the specific type/cause of a protocol error.
|
||||||
|
#[derive(PartialEq, Eq, Clone, Copy)] |
||||||
|
pub enum ProtocolError { |
||||||
|
/// Use of the wrong HTTP method (the WebSocket protocol requires the GET method be used).
|
||||||
|
WrongHttpMethod, |
||||||
|
/// Wrong HTTP version used (the WebSocket protocol requires version 1.1 or higher).
|
||||||
|
WrongHttpVersion, |
||||||
|
/// Missing `Connection: upgrade` HTTP header.
|
||||||
|
MissingConnectionUpgradeHeader, |
||||||
|
/// Missing `Upgrade: websocket` HTTP header.
|
||||||
|
MissingUpgradeWebSocketHeader, |
||||||
|
/// Missing `Sec-WebSocket-Version: 13` HTTP header.
|
||||||
|
MissingSecWebSocketVersionHeader, |
||||||
|
/// Missing `Sec-WebSocket-Key` HTTP header.
|
||||||
|
MissingSecWebSocketKey, |
||||||
|
/// The `Sec-WebSocket-Accept` header is either not present or does not specify the correct key value.
|
||||||
|
SecWebSocketAcceptKeyMismatch, |
||||||
|
/// Garbage data encountered after client request.
|
||||||
|
JunkAfterRequest, |
||||||
|
/// Custom responses must be unsuccessful.
|
||||||
|
CustomResponseSuccessful, |
||||||
|
/// No more data while still performing handshake.
|
||||||
|
HandshakeIncomplete, |
||||||
|
/// Wrapper around a [`httparse::Error`] value.
|
||||||
|
HttparseError(httparse::Error), |
||||||
|
/// Not allowed to send after having sent a closing frame.
|
||||||
|
SendAfterClosing, |
||||||
|
/// Remote sent data after sending a closing frame.
|
||||||
|
ReceivedAfterClosing, |
||||||
|
/// Reserved bits in frame header are non-zero.
|
||||||
|
NonZeroReservedBits, |
||||||
|
/// The server must close the connection when an unmasked frame is received.
|
||||||
|
UnmaskedFrameFromClient, |
||||||
|
/// The client must close the connection when a masked frame is received.
|
||||||
|
MaskedFrameFromServer, |
||||||
|
/// Control frames must not be fragmented.
|
||||||
|
FragmentedControlFrame, |
||||||
|
/// Control frames must have a payload of 125 bytes or less.
|
||||||
|
ControlFrameTooBig, |
||||||
|
/// Type of control frame not recognised.
|
||||||
|
UnknownControlFrameType(u8), |
||||||
|
/// Type of data frame not recognised.
|
||||||
|
UnknownDataFrameType(u8), |
||||||
|
/// Received a continue frame despite there being nothing to continue.
|
||||||
|
UnexpectedContinueFrame, |
||||||
|
/// Received data while waiting for more fragments.
|
||||||
|
ExpectedFragment(Data), |
||||||
|
/// Connection closed without performing the closing handshake.
|
||||||
|
ResetWithoutClosingHandshake, |
||||||
|
/// Encountered an invalid opcode.
|
||||||
|
InvalidOpcode(u8), |
||||||
|
/// The payload for the closing frame is invalid.
|
||||||
|
InvalidCloseSequence, |
||||||
|
} |
||||||
|
|
||||||
|
impl fmt::Debug for ProtocolError { |
||||||
|
#[inline] |
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||||
|
match *self { |
||||||
|
Self::WrongHttpMethod => { |
||||||
|
write!(f, "Unsupported HTTP method used - only GET is allowed") |
||||||
|
} |
||||||
|
Self::WrongHttpVersion => write!(f, "HTTP version must be 1.1 or higher"), |
||||||
|
Self::MissingConnectionUpgradeHeader => write!(f, "No \"Connection: upgrade\" header"), |
||||||
|
Self::MissingUpgradeWebSocketHeader => write!(f, "No \"Upgrade: websocket\" header"), |
||||||
|
Self::MissingSecWebSocketVersionHeader => { |
||||||
|
write!(f, "No \"Sec-WebSocket-Version: 13\" header") |
||||||
|
} |
||||||
|
Self::MissingSecWebSocketKey => write!(f, "No \"Sec-WebSocket-Key\" header"), |
||||||
|
Self::SecWebSocketAcceptKeyMismatch => { |
||||||
|
write!(f, "Key mismatch in \"Sec-WebSocket-Accept\" header") |
||||||
|
} |
||||||
|
Self::JunkAfterRequest => write!(f, "Junk after client request"), |
||||||
|
Self::CustomResponseSuccessful => write!(f, "Custom response must not be successful"), |
||||||
|
Self::HandshakeIncomplete => write!(f, "Handshake not finished"), |
||||||
|
Self::HttparseError(elem) => write!(f, "httparse error: {}", elem), |
||||||
|
Self::SendAfterClosing => write!(f, "Sending after closing is not allowed"), |
||||||
|
Self::ReceivedAfterClosing => write!(f, "Remote sent after having closed"), |
||||||
|
Self::NonZeroReservedBits => write!(f, "Reserved bits are non-zero"), |
||||||
|
Self::UnmaskedFrameFromClient => write!(f, "Received an unmasked frame from client"), |
||||||
|
Self::MaskedFrameFromServer => write!(f, "Received a masked frame from server"), |
||||||
|
Self::FragmentedControlFrame => write!(f, "Fragmented control frame"), |
||||||
|
Self::ControlFrameTooBig => { |
||||||
|
write!(f, "Control frame too big (payload must be 125 bytes or less)") |
||||||
|
} |
||||||
|
Self::UnknownControlFrameType(elem) => { |
||||||
|
write!(f, "Unknown control frame type: {}", elem) |
||||||
|
} |
||||||
|
Self::UnknownDataFrameType(elem) => write!(f, "Unknown data frame type: {}", elem), |
||||||
|
Self::UnexpectedContinueFrame => write!(f, "Continue frame but nothing to continue"), |
||||||
|
Self::ExpectedFragment(elem) => { |
||||||
|
write!(f, "While waiting for more fragments received: {}", elem) |
||||||
|
} |
||||||
|
Self::ResetWithoutClosingHandshake => { |
||||||
|
write!(f, "Connection reset without closing handshake") |
||||||
|
} |
||||||
|
Self::InvalidOpcode(elem) => write!(f, "Encountered invalid opcode: {}", elem), |
||||||
|
Self::InvalidCloseSequence => write!(f, "Invalid close sequence"), |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl fmt::Display for ProtocolError { |
||||||
|
#[inline] |
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||||
|
fmt::Debug::fmt(self, f) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl std::error::Error for ProtocolError {} |
@ -0,0 +1,66 @@ |
|||||||
|
use std::fmt; |
||||||
|
|
||||||
|
/// TLS errors.
|
||||||
|
///
|
||||||
|
/// Note that even if you enable only the rustls-based TLS support, the error at runtime could still
|
||||||
|
/// be `Native`, as another crate in the dependency graph may enable native TLS support.
|
||||||
|
#[allow(missing_copy_implementations)] |
||||||
|
#[non_exhaustive] |
||||||
|
pub enum TlsError { |
||||||
|
/// Native TLS error.
|
||||||
|
#[cfg(feature = "native-tls")] |
||||||
|
Native(native_tls_crate::Error), |
||||||
|
/// Rustls error.
|
||||||
|
#[cfg(feature = "rustls-tls")] |
||||||
|
Rustls(rustls::TLSError), |
||||||
|
/// DNS name resolution error.
|
||||||
|
#[cfg(feature = "rustls-tls")] |
||||||
|
Dns(webpki::InvalidDNSNameError), |
||||||
|
} |
||||||
|
|
||||||
|
impl fmt::Debug for TlsError { |
||||||
|
#[inline] |
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||||
|
match *self { |
||||||
|
#[cfg(feature = "native-tls")] |
||||||
|
Self::Native(ref elem) => write!(f, "native-tls error: {}", elem), |
||||||
|
#[cfg(feature = "rustls-tls")] |
||||||
|
Self::Rustls(ref elem) => write!(f, "rustls error: {}", elem), |
||||||
|
#[cfg(feature = "rustls-tls")] |
||||||
|
Self::Dns(ref elem) => write!(f, "Invalid DNS name: {}", elem), |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#[cfg(feature = "native-tls")] |
||||||
|
impl From<native_tls_crate::Error> for TlsError { |
||||||
|
#[inline] |
||||||
|
fn from(from: native_tls_crate::Error) -> Self { |
||||||
|
Self::Native(from) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#[cfg(feature = "rustls-tls")] |
||||||
|
impl From<rustls::TLSError> for TlsError { |
||||||
|
#[inline] |
||||||
|
fn from(from: rustls::TLSError) -> Self { |
||||||
|
Self::Rustls(from) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#[cfg(feature = "rustls-tls")] |
||||||
|
impl From<webpki::InvalidDNSNameError> for TlsError { |
||||||
|
#[inline] |
||||||
|
fn from(from: webpki::InvalidDNSNameError) -> Self { |
||||||
|
Self::Dns(from) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl fmt::Display for TlsError { |
||||||
|
#[inline] |
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||||
|
fmt::Debug::fmt(self, f) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl std::error::Error for TlsError {} |
@ -0,0 +1,41 @@ |
|||||||
|
use std::fmt; |
||||||
|
|
||||||
|
/// Indicates the specific type/cause of URL error.
|
||||||
|
#[derive(PartialEq, Eq)] |
||||||
|
pub enum UrlError { |
||||||
|
/// TLS is used despite not being compiled with the TLS feature enabled.
|
||||||
|
TlsFeatureNotEnabled, |
||||||
|
/// The URL does not include a host name.
|
||||||
|
NoHostName, |
||||||
|
/// Failed to connect with this URL.
|
||||||
|
UnableToConnect(String), |
||||||
|
/// Unsupported URL scheme used (only `ws://` or `wss://` may be used).
|
||||||
|
UnsupportedUrlScheme, |
||||||
|
/// The URL host name, though included, is empty.
|
||||||
|
EmptyHostName, |
||||||
|
/// The URL does not include a path/query.
|
||||||
|
NoPathOrQuery, |
||||||
|
} |
||||||
|
|
||||||
|
impl fmt::Debug for UrlError { |
||||||
|
#[inline] |
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||||
|
match *self { |
||||||
|
Self::TlsFeatureNotEnabled => write!(f, "TLS support not compiled in"), |
||||||
|
Self::NoHostName => write!(f, "No host name in the URL"), |
||||||
|
Self::UnableToConnect(ref elem) => write!(f, "Unable to connect to {}", elem), |
||||||
|
Self::UnsupportedUrlScheme => write!(f, "URL scheme not supported"), |
||||||
|
Self::EmptyHostName => write!(f, "URL contains empty host name"), |
||||||
|
Self::NoPathOrQuery => write!(f, "No path/query in URL"), |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl fmt::Display for UrlError { |
||||||
|
#[inline] |
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
||||||
|
fmt::Debug::fmt(self, f) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
impl std::error::Error for UrlError {} |
Loading…
Reference in new issue