1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//! h2 error/s
/// RFC 9113 s.7 canonical H2 Errors
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum H2ErrorOut {
/// **NO_ERROR (0x00)**
///
/// ##
/// The associated condition is not a result of an error. For example, a GOAWAY might include this code to indicate graceful shutdown of a connection.
No,
/// **PROTOCOL_ERROR (0x01)**
///
/// ##
/// The endpoint detected an unspecific protocol error. This error is for use when a more specific error code is not available.
Protocol,
/// **INTERNAL_ERROR (0x02)**
///
/// ##
/// The endpoint encountered an unexpected internal error.
Internal,
/// **FLOW_CONTROL_ERROR (0x03)**
///
/// ##
/// The endpoint detected that its peer violated the flow-control protocol.
FlowControl,
/// **SETTINGS_TIMEOUT (0x04)**
///
/// ##
/// The endpoint sent a SETTINGS frame but did not receive a response in a timely manner. See Section 6.5.3 ("Settings Synchronization").
SettingsTimeout,
/// **STREAM_CLOSED (0x05)**
///
/// ##
/// The endpoint received a frame with an invalid size.
StreamClosed,
/// **FRAME_SIZE_ERROR (0x06)**
///
/// ##
/// The endpoint received a frame with an invalid size.
FrameSize,
/// **REFUSED_STREAM (0x07)**
///
/// ##
/// The endpoint refused the stream prior to performing any application processing (see Section 8.7 for details).
RefusedStream,
/// **CANCEL (0x08)**
///
/// ##
/// The endpoint uses this error code to indicate that the stream is no longer needed.
Cancel,
/// **COMPRESSION_ERROR (0x09)**
///
/// ##
/// The endpoint is unable to maintain the field section compression context for the connection.
Compression,
/// **CONNECT_ERROR (0x0a)**
///
/// ##
/// The connection established in response to a CONNECT request (Section 8.5) was reset or abnormally closed.
Connect,
/// **ENHANCE_YOUR_CALM (0x0b)**
///
/// ##
/// The endpoint detected that its peer is exhibiting a behavior that might be generating excessive load.
EnhanceYourCalm,
/// **INADEQUATE_SECURITY (0x0c)**
///
/// ##
/// The underlying transport has properties that do not meet minimum security requirements (see Section 9.2).
InadequateSecurity,
/// **HTTP_1_1_REQUIRED (0x0d)**
///
/// ##
/// The endpoint requires that HTTP/1.1 be used instead of HTTP/2.
Http11Required,
/// Unknown to impl / non-RFC Error must be treated as Internal Error
Unknown(u8),
}
impl From<Option<H2ErrorOut>> for H2ErrorOut {
#[inline]
fn from(oe: Option<H2ErrorOut>) -> H2ErrorOut {
match oe {
Some(e) => e,
None => H2ErrorOut::Internal,
}
}
}
impl H2ErrorOut {
/// As a byte
#[inline]
pub fn as_u8(&self) -> u8 {
match self {
Self::No => 0x00,
Self::Protocol => 0x01,
Self::Internal => 0x02,
Self::FlowControl => 0x03,
Self::SettingsTimeout => 0x04,
Self::StreamClosed => 0x05,
Self::FrameSize => 0x06,
Self::RefusedStream => 0x07,
Self::Cancel => 0x08,
Self::Compression => 0x09,
Self::Connect => 0x0a,
Self::EnhanceYourCalm => 0x0b,
Self::InadequateSecurity => 0x0c,
Self::Http11Required => 0x0d,
Self::Unknown(u) => *u,
}
}
/// Construct from a byte
#[inline]
pub fn from_u8(u: u8) -> Self {
match u {
0x00 => Self::No,
0x01 => Self::Protocol,
0x02 => Self::Internal,
0x03 => Self::FlowControl,
0x04 => Self::SettingsTimeout,
0x05 => Self::StreamClosed,
0x06 => Self::FrameSize,
0x07 => Self::RefusedStream,
0x08 => Self::Cancel,
0x09 => Self::Compression,
0x0a => Self::Connect,
0x0b => Self::EnhanceYourCalm,
0x0c => Self::InadequateSecurity,
0x0d => Self::Http11Required,
_ => Self::Unknown(u),
}
}
}
/// H2 Errors
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum H2Error {
/// Settings related error, typically due to RFC 9113 s. 6.5.2 rules.
Settings(H2SettingsError),
}
/// Frame building errors.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum BuilderError {
/// Builder output would overflow the maximum size allowed.
Overflow,
}
/// Frame Parsing Errors
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum ParsingError {
/// Invalid StreamId
InvalidStreamId,
/// Parse payload was called with invalid state
ExpectedStatePayload,
/// Parse was called with invalid state
InvalidState,
}
/// H2 Settings Error
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum H2SettingsError {
/// Multiple Payloads when only one allowed
DuplicatePayload,
/// Invalid settings payload
InvalidPayload,
/// Enable push must be either 0 or 1.
InvalidEnablePush,
/// Maximum initial window size is 2^31-1.
/// This must be treated as Flow Control Error
FlowControlError,
/// Maximum allowed frame size must be between 2^14 and 2^24-1.
/// This must be treated as Protcol Error
ProtocolError,
}