http_box/http1/
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/// Type that handles HTTP/1.x parser events.
18#[allow(unused_variables)]
19pub trait HttpHandler {
20    /// Retrieve the content length.
21    ///
22    /// **Called When::**
23    ///
24    /// Within multipart parsing, after each boundary's head data has been parsed.
25    fn content_length(&mut self) -> Option<usize> {
26        None
27    }
28
29    /// Callback that is executed when body parsing has completed successfully.
30    ///
31    /// **Returns:**
32    ///
33    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
34    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
35    fn on_body_finished(&mut self) -> bool {
36        true
37    }
38
39    /// Callback that is executed when a new chunk section has been located. This is executed
40    /// prior to the length, extensions, and data.
41    ///
42    /// **Returns:**
43    ///
44    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
45    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
46    fn on_chunk_begin(&mut self) -> bool {
47        true
48    }
49
50    /// Callback that is executed when chunk encoded data has been located.
51    ///
52    /// *Note:* This may be executed multiple times in order to supply the entire segment.
53    ///
54    /// **Returns:**
55    ///
56    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
57    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
58    fn on_chunk_data(&mut self, data: &[u8]) -> bool {
59        true
60    }
61
62    /// Callback that is executed when parsing an individual chunk extension name/value pair has
63    /// completed successfully.
64    ///
65    /// **Returns:**
66    ///
67    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
68    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
69    fn on_chunk_extension_finished(&mut self) -> bool {
70        true
71    }
72
73    /// Callback that is executed when a chunk extension name has been located.
74    ///
75    /// *Note:* This may be executed multiple times in order to supply the entire segment.
76    ///
77    /// **Returns:**
78    ///
79    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
80    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
81    fn on_chunk_extension_name(&mut self, name: &[u8]) -> bool {
82        true
83    }
84
85    /// Callback that is executed when a chunk extension value has been located.
86    ///
87    /// *Note:* This may be executed multiple times in order to supply the entire segment.
88    ///
89    /// **Returns:**
90    ///
91    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
92    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
93    fn on_chunk_extension_value(&mut self, value: &[u8]) -> bool {
94        true
95    }
96
97    /// Callback that is executed when parsing all chunk extensions has completed successfully.
98    ///
99    /// **Returns:**
100    ///
101    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
102    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
103    fn on_chunk_extensions_finished(&mut self) -> bool {
104        true
105    }
106
107    /// Callback that is executed when a chunk length has been located.
108    ///
109    /// **Returns:**
110    ///
111    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
112    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
113    fn on_chunk_length(&mut self, size: usize) -> bool {
114        true
115    }
116
117    /// Callback that is executed when a header name has been located.
118    ///
119    /// *Note:* This may be executed multiple times in order to supply the entire segment.
120    ///
121    /// **Returns:**
122    ///
123    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
124    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
125    ///
126    /// **Called When:**
127    ///
128    /// During head parsing, multipart parsing of headers for each piece of data, or at the end of
129    /// chunk encoded data when trailers are present.
130    fn on_header_name(&mut self, name: &[u8]) -> bool {
131        true
132    }
133
134    /// Callback that is executed when a header value has been located.
135    ///
136    /// *Note:* This may be executed multiple times in order to supply the entire segment.
137    ///
138    /// **Returns:**
139    ///
140    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
141    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
142    ///
143    /// **Called When:**
144    ///
145    /// During head parsing, multipart parsing of headers for each piece of data, or at the end of
146    /// chunk encoded data when trailers are present.
147    fn on_header_value(&mut self, value: &[u8]) -> bool {
148        true
149    }
150
151    /// Callback that is executed when header parsing has completed successfully.
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    ///
158    /// **Called When:**
159    ///
160    /// During head parsing, multipart parsing of headers for each piece of data, or at the end of
161    /// chunk encoded data when trailers are present.
162    fn on_headers_finished(&mut self) -> bool {
163        true
164    }
165
166    /// Callback that is executed when parsing the initial request/response line has completed
167    /// successfully.
168    ///
169    /// **Returns:**
170    ///
171    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
172    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
173    fn on_initial_finished(&mut self) -> bool {
174        true
175    }
176
177    /// Callback that is executed when a request method has been located.
178    ///
179    /// *Note:* This may be executed multiple times in order to supply the entire segment.
180    ///
181    /// **Returns:**
182    ///
183    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
184    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
185    fn on_method(&mut self, method: &[u8]) -> bool {
186        true
187    }
188
189    /// Callback that is executed when a new multipart section has been located. This is executed
190    /// prior to any headers.
191    ///
192    /// **Returns:**
193    ///
194    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
195    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
196    fn on_multipart_begin(&mut self) -> bool {
197        true
198    }
199
200    /// Callback that is executed when multipart data has been located.
201    ///
202    /// *Note:* This may be executed multiple times in order to supply the entire segment.
203    ///
204    /// **Returns:**
205    ///
206    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
207    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
208    fn on_multipart_data(&mut self, data: &[u8]) -> bool {
209        true
210    }
211
212    /// Callback that is executed when a response status has been located.
213    ///
214    /// *Note:* This may be executed multiple times in order to supply the entire segment.
215    ///
216    /// **Returns:**
217    ///
218    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
219    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
220    fn on_status(&mut self, status: &[u8]) -> bool {
221        true
222    }
223
224    /// Callback that is executed when a response status code has been located.
225    ///
226    /// **Returns:**
227    ///
228    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
229    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
230    fn on_status_code(&mut self, code: u16) -> bool {
231        true
232    }
233
234    /// Callback that is executed when a request URL has been located.
235    ///
236    /// *Note:* This may be executed multiple times in order to supply the entire segment.
237    ///
238    /// **Returns:**
239    ///
240    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
241    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
242    fn on_url(&mut self, url: &[u8]) -> bool {
243        true
244    }
245
246    /// Callback that is executed when a new URL encoded name/value pair has been located.
247    ///
248    /// **Returns:**
249    ///
250    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
251    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
252    fn on_url_encoded_begin(&mut self) -> bool {
253        true
254    }
255
256    /// Callback that is executed when a URL encoded name has been located.
257    ///
258    /// *Note:* This may be executed multiple times in order to supply the entire segment.
259    ///
260    /// **Returns:**
261    ///
262    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
263    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
264    fn on_url_encoded_name(&mut self, name: &[u8]) -> bool {
265        true
266    }
267
268    /// Callback that is executed when a URL encoded value has been located.
269    ///
270    /// *Note:* This may be executed multiple times in order to supply the entire segment.
271    ///
272    /// **Returns:**
273    ///
274    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
275    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
276    fn on_url_encoded_value(&mut self, value: &[u8]) -> bool {
277        true
278    }
279
280    /// Callback that is executed when the HTTP version has been located during the initial request
281    /// or response line.
282    ///
283    /// **Returns:**
284    ///
285    /// `true` when parsing should continue, `false` to exit the parser function prematurely with
286    /// [`Success::Callback`](../fsm/enum.Success.html#variant.Callback).
287    fn on_version(&mut self, major: u16, minor: u16) -> bool {
288        true
289    }
290}