http_box/http2/http_handler.rs
1// +-----------------------------------------------------------------------------------------------+
2// | Copyright 2016 Sean Kerr |
3// | |
4// | Licensed under the Apache License, Version 2.0 (the "License"); |
5// | you may not use this file except in compliance with the License. |
6// | You may obtain a copy of the License at |
7// | |
8// | http://www.apache.org/licenses/LICENSE-2.0 |
9// | |
10// | Unless required by applicable law or agreed to in writing, software |
11// | distributed under the License is distributed on an "AS IS" BASIS, |
12// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13// | See the License for the specific language governing permissions and |
14// | limitations under the License. |
15// +-----------------------------------------------------------------------------------------------+
16
17//! HTTP 2.x callback trait.
18
19/// Type that handles HTTP/2.x parser events.
20#[allow(unused_variables)]
21pub trait HttpHandler {
22 /// Callback that is executed when a data frame has been located.
23 ///
24 /// *Note:* This may be executed multiple times in order to supply the entire segment.
25 ///
26 /// **Arguments:**
27 ///
28 /// **`data`**
29 ///
30 /// The data.
31 ///
32 /// **`finished`**
33 ///
34 /// Indicates this is the last chunk of the data.
35 ///
36 /// **Returns:**
37 ///
38 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
39 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
40 fn on_data(&mut self, data: &[u8], finished: bool) -> bool {
41 true
42 }
43
44 /// Callback that is executed when a new frame format has been located.
45 ///
46 /// **Arguments:**
47 ///
48 /// **`payload_length`**
49 ///
50 /// The payload length.
51 ///
52 /// **`frame_type`**
53 ///
54 /// The type.
55 ///
56 /// **`flags`**
57 ///
58 /// The flags.
59 ///
60 /// **`stream_id`**
61 ///
62 /// The stream identifier.
63 ///
64 /// **Returns:**
65 ///
66 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
67 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
68 fn on_frame_format(&mut self, payload_length: u32, frame_type: u8, flags: u8, stream_id: u32)
69 -> bool {
70 true
71 }
72
73 /// Callback that is executed when a go away frame has been located.
74 ///
75 /// **Arguments:**
76 ///
77 /// **`stream_id`**
78 ///
79 /// The stream identifier.
80 ///
81 /// **`error_code`**
82 ///
83 /// The error code.
84 ///
85 /// **Returns:**
86 ///
87 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
88 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
89 fn on_go_away(&mut self, stream_id: u32, error_code: u32) -> bool {
90 true
91 }
92
93 /// Callback that is executed when go away frame debug data has been located.
94 ///
95 /// *Note:* This may be executed multiple times in order to supply the entire segment.
96 ///
97 /// **Arguments:**
98 ///
99 /// **`data`**
100 ///
101 /// The data.
102 ///
103 /// **`finished`**
104 ///
105 /// Indicates this is the last chunk of the data.
106 ///
107 /// **Returns:**
108 ///
109 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
110 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
111 fn on_go_away_debug_data(&mut self, data: &[u8], finished: bool) -> bool {
112 true
113 }
114
115 /// Callback that is executed when a headers frame has been located.
116 ///
117 /// **Arguments:**
118 ///
119 /// **`exclusive`**
120 ///
121 /// Indicates the stream identifier is exclusive.
122 ///
123 /// **`stream_id`**
124 ///
125 /// The stream identifier.
126 ///
127 /// **`weight`**
128 ///
129 /// The weight.
130 ///
131 /// **Returns:**
132 ///
133 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
134 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
135 fn on_headers(&mut self, exclusive: bool, stream_id: u32, weight: u8) -> bool {
136 true
137 }
138
139 /// Callback that is executed when a headers frame fragment has been located.
140 ///
141 /// *Note:* This may be executed multiple times in order to supply the entire segment.
142 ///
143 /// **Arguments:**
144 ///
145 /// **`fragment`**
146 ///
147 /// The fragment.
148 ///
149 /// **`finished`**
150 ///
151 /// Indicates this is the last chunk of the fragment.
152 ///
153 /// **Returns:**
154 ///
155 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
156 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
157 fn on_headers_fragment(&mut self, fragment: &[u8], finished: bool) -> bool {
158 true
159 }
160
161 /// Callback that is executed when a ping frame has been located.
162 ///
163 /// *Note:* This may be executed multiple times in order to supply the entire segment.
164 ///
165 /// **Arguments:**
166 ///
167 /// **`data`**
168 ///
169 /// The data.
170 ///
171 /// **`finished`**
172 ///
173 /// Indicates this is the last chunk of the data.
174 ///
175 /// **Returns:**
176 ///
177 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
178 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
179 fn on_ping(&mut self, data: &[u8], finished: bool) -> bool {
180 true
181 }
182
183 /// Callback that is executed when a priority frame has been located.
184 ///
185 /// **Arguments:**
186 ///
187 /// **`exclusive`**
188 ///
189 /// Indicates the stream identifier is exclusive.
190 ///
191 /// **`stream_id`**
192 ///
193 /// The stream identifier.
194 ///
195 /// **`weight`**
196 ///
197 /// The weight.
198 ///
199 /// **Returns:**
200 ///
201 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
202 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
203 fn on_priority(&mut self, exclusive: bool, stream_id: u32, weight: u8) -> bool {
204 true
205 }
206
207 /// Callback that is executed when a push promise frame has been located.
208 ///
209 /// **Arguments:**
210 ///
211 /// **`stream_id`**
212 ///
213 /// The stream identifier.
214 ///
215 /// **Returns:**
216 ///
217 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
218 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
219 fn on_push_promise(&mut self, stream_id: u32) -> bool {
220 true
221 }
222
223 /// Callback that is executed when a rst stream frame has been located.
224 ///
225 /// **Arguments:**
226 ///
227 /// **`error_code`**
228 ///
229 /// The error code.
230 ///
231 /// **Returns:**
232 ///
233 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
234 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
235 fn on_rst_stream(&mut self, error_code: u32) -> bool {
236 true
237 }
238
239 /// Callback that is executed when a settings frame has been located.
240 ///
241 /// **Arguments:**
242 ///
243 /// **`id`**
244 ///
245 /// The identifier.
246 ///
247 /// **`value`**
248 ///
249 /// The value.
250 ///
251 /// **Returns:**
252 ///
253 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
254 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
255 fn on_settings(&mut self, id: u16, value: u32) -> bool {
256 true
257 }
258
259 /// Callback that is executed when an unsupported frame has been located.
260 ///
261 /// *Note:* This may be executed multiple times in order to supply the entire segment.
262 ///
263 /// **Arguments:**
264 ///
265 /// **`data`**
266 ///
267 /// The data.
268 ///
269 /// **`finished`**
270 ///
271 /// Indicates this is the last chunk of the data.
272 ///
273 /// **Returns:**
274 ///
275 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
276 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
277 fn on_unsupported(&mut self, data: &[u8], finished: bool) -> bool {
278 true
279 }
280
281 /// Callback that is executed when a window update frame has been located.
282 ///
283 /// **Arguments:**
284 ///
285 /// **`size_increment`**
286 ///
287 /// The size increment.
288 ///
289 /// **Returns:**
290 ///
291 /// `true` when parsing should continue, `false` to exit the parser function prematurely with
292 /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
293 fn on_window_update(&mut self, size_increment: u32) -> bool {
294 true
295 }
296}