1use crate::frame::Frame;
2use pki_types::InvalidDnsNameError;
3use std::io;
4use std::string::FromUtf8Error;
5use thiserror::Error;
6use tokio::sync::mpsc::error::SendError;
7use tokio::time::error::Elapsed;
8use url::ParseError;
9
10#[derive(Error, Debug)]
11pub enum Error {
12 #[error("{source}")]
14 SendError {
15 #[from]
16 source: SendError<Frame>,
17 },
18
19 #[error("channel communication error")]
20 CommunicationError,
21
22 #[error("{source}")]
24 Timeout {
25 #[from]
26 source: Elapsed,
27 },
28
29 #[error("IO Error happened: {source}")]
30 IOError {
31 #[from]
32 source: io::Error,
33 },
34
35 #[error("{source}")]
36 FromUtf8Error {
37 #[from]
38 source: FromUtf8Error,
39 },
40
41 #[error("Invalid handshake request method and version")]
43 InvalidHTTPHandshake,
44
45 #[error("Connection: Upgrade header missing in the request")]
46 NoConnectionHeaderPresent,
47
48 #[error("Upgrade: websocket header missing in the request")]
49 NoUpgradeHeaderPresent,
50
51 #[error("Host header missing in the request")]
52 NoHostHeaderPresent,
53
54 #[error("Couldn't find Sec-WebSocket-Key header in the request")]
55 NoSecWebsocketKey,
56
57 #[error("Server didn't upgrade the connection")]
58 NoUpgrade,
59
60 #[error("Sever didn't send a valid Sec-WebSocket-Accept key")]
61 InvalidAcceptKey,
62
63 #[error("RSV not zero")]
65 RSVNotZero,
66
67 #[error("Control frames must not be fragmented")]
68 ControlFramesFragmented,
69
70 #[error("Control frame with invalid payload size, can be greater than 125")]
71 ControlFramePayloadSize,
72
73 #[error("fragment_size: `{0}` can't be greater than max_frame_size: `{0}`")]
74 CustomFragmentSizeExceeded(usize, usize),
75
76 #[error("Max frame size reached")]
77 MaxFrameSize,
78
79 #[error("Max message size reached")]
80 MaxMessageSize,
81
82 #[error("Invalid frame while there is a fragmented message in progress")]
84 InvalidFrameFragmentation,
85
86 #[error("Incoming fragmented message but there is one already in progress")]
87 FragmentedInProgress,
88
89 #[error("Invalid continuation frame: no fragmented message to continue")]
90 InvalidContinuationFrame,
91
92 #[error("Invalid Opcode")]
93 InvalidOpcode,
94
95 #[error("Failed to parse HTTP headers")]
97 HttpParseError,
98
99 #[error("Invalid HTTP request line")]
100 InvalidHTTPRequestLine,
101
102 #[error("Missing HTTP method")]
103 MissingHTTPMethod,
104
105 #[error("Missing HTTP URI")]
106 MissingHTTPUri,
107
108 #[error("Missing HTTP version")]
109 MissingHTTPVersion,
110
111 #[error("Invalid Content-Length")]
112 InvalidContentLength,
113
114 #[error("{source}")]
115 URLParseError {
116 #[from]
117 source: ParseError,
118 },
119
120 #[error("Invalid scheme in WebSocket URL")]
121 InvalidSchemeURL,
122
123 #[error("URL has no host")]
124 URLNoHost,
125
126 #[error("URL has no port")]
127 URLNoPort,
128
129 #[error("Incomplete HTTP request")]
130 IncompleteHTTPRequest,
131
132 #[error("{source}")]
134 DomainError {
135 #[from]
136 source: InvalidDnsNameError,
137 },
138
139 #[error("use_tls = `{0}` argument does not match the passed URL scheme: `{1}`")]
140 SchemeAgainstTlsConfig(bool, String),
141
142 #[error("max_window_bits should be a value between 8 and 15")]
144 InvalidMaxWindowBits,
145}