http_box/http1/
parser_state.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 1.x parser states.
18
19/// Parser states.
20#[derive(Clone,Copy,Debug,PartialEq)]
21#[repr(u8)]
22pub enum ParserState {
23    /// An error was returned from a call to `Parser::parse()`.
24    Dead,
25
26    /// Stripping linear white space before request/response detection.
27    StripDetect,
28
29    /// Detect request/response byte 1.
30    Detect1,
31
32    /// Detect request/response byte 2.
33    Detect2,
34
35    /// Detect request/response byte 3.
36    Detect3,
37
38    /// Detect request/response byte 4.
39    Detect4,
40
41    /// Detect request/response byte 5.
42    Detect5,
43
44    // ---------------------------------------------------------------------------------------------
45    // REQUEST
46    // ---------------------------------------------------------------------------------------------
47
48    /// Parsing request method.
49    RequestMethod,
50
51    /// Parsing request URL byte 1.
52    RequestUrl1,
53
54    /// Parsing request URL byte 2+.
55    RequestUrl2,
56
57    /// Parsing request HTTP version byte 1.
58    RequestHttp1,
59
60    /// Parsing request HTTP version byte 2.
61    RequestHttp2,
62
63    /// Parsing request HTTP version byte 3.
64    RequestHttp3,
65
66    /// Parsing request HTTP version byte 4.
67    RequestHttp4,
68
69    /// Parsing request HTTP version byte 5.
70    RequestHttp5,
71
72    /// Parsing request HTTP major version byte 1.
73    RequestVersionMajor1,
74
75    /// Parsing request HTTP major version byte 2.
76    RequestVersionMajor2,
77
78    /// Parsing request HTTP major version byte 3.
79    RequestVersionMajor3,
80
81    /// Parsing period between HTTP major and minor versions.
82    RequestVersionPeriod,
83
84    /// Parsing request HTTP minor version byte 1.
85    RequestVersionMinor1,
86
87    /// Parsing request HTTP minor version byte 2.
88    RequestVersionMinor2,
89
90    /// Parsing request HTTP minor version byte 3.
91    RequestVersionMinor3,
92
93    /// Parsing carriage return after request HTTP minor version.
94    RequestVersionCr,
95
96    // ---------------------------------------------------------------------------------------------
97    // RESPONSE
98    // ---------------------------------------------------------------------------------------------
99
100    /// Parsing response HTTP major version byte 1.
101    ResponseVersionMajor1,
102
103    /// Parsing response HTTP major version byte 2.
104    ResponseVersionMajor2,
105
106    /// Parsing response HTTP major version byte 3.
107    ResponseVersionMajor3,
108
109    /// Parsing period between HTTP major and minor versions.
110    ResponseVersionPeriod,
111
112    /// Parsing response HTTP minor version byte 1.
113    ResponseVersionMinor1,
114
115    /// Parsing response HTTP minor version byte 2.
116    ResponseVersionMinor2,
117
118    /// Parsing response HTTP minor version byte 3.
119    ResponseVersionMinor3,
120
121    /// Parsing space after response HTTP minor version.
122    ResponseVersionSpace,
123
124    /// Parsing response status code byte 1.
125    ResponseStatusCode1,
126
127    /// Parsing response status code byte 2.
128    ResponseStatusCode2,
129
130    /// Parsing response status code byte 3.
131    ResponseStatusCode3,
132
133    /// Parsing space after response status code.
134    ResponseStatusCodeSpace,
135
136    /// Parsing response status byte 1.
137    ResponseStatus1,
138
139    /// Parsing response status byte 2+.
140    ResponseStatus2,
141
142    // ---------------------------------------------------------------------------------------------
143    // HEADERS
144    // ---------------------------------------------------------------------------------------------
145
146    /// Parsing initial request/response line has finished.
147    InitialEnd,
148
149    /// Parsing line feed after initial request/response line.
150    InitialLf,
151
152    /// Checking header name to see if it starts with a space or tab (multiline value).
153    CheckHeaderName,
154
155    /// Parsing first byte of header name.
156    FirstHeaderName,
157
158    /// Parsing upper-cased header name.
159    UpperHeaderName,
160
161    /// Parsing lower-cased header name.
162    LowerHeaderName,
163
164    /// Stripping linear white space before header value.
165    StripHeaderValue,
166
167    /// Parsing header value.
168    HeaderValue,
169
170    /// Parsing quoted header value.
171    HeaderQuotedValue,
172
173    /// Parsing escaped header value.
174    HeaderEscapedValue,
175
176    /// Parsing first carriage return after status line or header value.
177    HeaderCr1,
178
179    /// Parsing first line feed after status line or header value.
180    HeaderLf1,
181
182    /// Parsing second carriage return after status line or header value.
183    HeaderCr2,
184
185    /// Parsing second line feed after status line or header value.
186    HeaderLf2,
187
188    /// Processing end-of-header flag checks.
189    HeaderEnd,
190
191    // ---------------------------------------------------------------------------------------------
192    // CHUNKED TRANSFER
193    // ---------------------------------------------------------------------------------------------
194
195    /// Parsing chunk length byte 1.
196    ChunkLength1,
197
198    /// Parsing chunk length byte 2.
199    ChunkLength2,
200
201    /// Parsing chunk length byte 3.
202    ChunkLength3,
203
204    /// Parsing chunk length byte 4.
205    ChunkLength4,
206
207    /// Parsing chunk length byte 5.
208    ChunkLength5,
209
210    /// Parsing chunk length byte 6.
211    ChunkLength6,
212
213    /// Parsing chunk length byte 7.
214    ChunkLength7,
215
216    /// Parsing chunk length byte 8.
217    ChunkLength8,
218
219    /// Parsing chunk length carriage return or semi-colon.
220    ChunkLengthCr,
221
222    /// Stripping linear white space before chunk extension name.
223    StripChunkExtensionName,
224
225    /// Parsing upper-cased chunk extension.
226    UpperChunkExtensionName,
227
228    /// Parsing lower-cased chunk extension.
229    LowerChunkExtensionName,
230
231    /// Stripping linear white space before chunk extension value.
232    StripChunkExtensionValue,
233
234    /// Parsing chunk extension value.
235    ChunkExtensionValue,
236
237    /// Parsing quoted chunk extension value.
238    ChunkExtensionQuotedValue,
239
240    /// Parsing escaped chunk extension value.
241    ChunkExtensionEscapedValue,
242
243    /// End of chunk extension.
244    ChunkExtensionFinished,
245
246    /// End of all chunk extensions.
247    ChunkExtensionsFinished,
248
249    /// Parsing line feed after chunk length.
250    ChunkLengthLf,
251
252    /// Parsing chunk data.
253    ChunkData,
254
255    /// Parsing carriage return after chunk data.
256    ChunkDataCr,
257
258    /// Parsing line feed after chunk data.
259    ChunkDataLf,
260
261    // ---------------------------------------------------------------------------------------------
262    // MULTIPART
263    // ---------------------------------------------------------------------------------------------
264
265    /// Parsing pre boundary hyphen 1.
266    MultipartHyphen1,
267
268    /// Parsing pre boundary hyphen 2.
269    MultipartHyphen2,
270
271    /// Parsing multipart boundary.
272    MultipartBoundary,
273
274    /// Detecting multipart data parsing mechanism.
275    MultipartDetectData,
276
277    /// Parsing multipart data by byte.
278    MultipartDataByByte,
279
280    /// Parsing multipart data by content length.
281    MultipartDataByLength,
282
283    /// Parsing carriage return after data by length.
284    MultipartDataByLengthCr,
285
286    /// Parsing line feed after data by length.
287    MultipartDataByLengthLf,
288
289    /// Parsing potential line feed after data by byte.
290    MultipartDataByByteLf,
291
292    /// Parsing post boundary carriage return or hyphen.
293    MultipartBoundaryCr,
294
295    /// Parsing post boundary line feed.
296    MultipartBoundaryLf,
297
298    /// Parsing last boundary second hyphen that indicates end of multipart body.
299    MultipartEnd,
300
301    // ---------------------------------------------------------------------------------------------
302    // URL ENCODED
303    // ---------------------------------------------------------------------------------------------
304
305    /// Parsing first byte of URL encoded name.
306    FirstUrlEncodedName,
307
308    /// Parsing URL encoded name.
309    UrlEncodedName,
310
311    /// Parsing URL encoded name hex sequence byte 1.
312    UrlEncodedNameHex1,
313
314    /// Parsing URL encoded name hex sequence byte 2.
315    UrlEncodedNameHex2,
316
317    /// Parsing URL encoded name plus sign.
318    UrlEncodedNamePlus,
319
320    /// Parsing URL encoded value.
321    UrlEncodedValue,
322
323    /// Parsing URL encoded value hex sequence byte 1.
324    UrlEncodedValueHex1,
325
326    /// Parsing URL encoded value hex sequence byte 2.
327    UrlEncodedValueHex2,
328
329    /// Parsing URL encoded value plus sign.
330    UrlEncodedValuePlus,
331
332    // ---------------------------------------------------------------------------------------------
333    // FINISHED
334    // ---------------------------------------------------------------------------------------------
335
336    /// End of body parsing.
337    BodyFinished,
338
339    /// Parsing entire message has finished.
340    Finished
341}
342
343// -------------------------------------------------------------------------------------------------
344
345/// State listing in parsing order.
346///
347/// This is a helper type that will simplify state tracking in custom
348/// [HttpHandler](trait.HttpHandler.html) implementations.
349#[derive(Clone,Copy,PartialEq)]
350#[repr(u8)]
351pub enum State {
352    None,
353
354    // ---------------------------------------------------------------------------------------------
355    // STATUS LINE STATES
356    // ---------------------------------------------------------------------------------------------
357
358    /// Request method.
359    RequestMethod,
360
361    /// Request URL.
362    RequestUrl,
363
364    /// Request HTTP version.
365    RequestVersion,
366
367    /// Response HTTP version.
368    ResponseVersion,
369
370    /// Response status code.
371    ResponseStatusCode,
372
373    /// Response status.
374    ResponseStatus,
375
376    // ---------------------------------------------------------------------------------------------
377    // HEADER STATES
378    // ---------------------------------------------------------------------------------------------
379
380    /// Header name.
381    HeaderName,
382
383    /// Header value.
384    HeaderValue,
385
386    // ---------------------------------------------------------------------------------------------
387    // CHUNK TRANSFER ENCODING STATES
388    // ---------------------------------------------------------------------------------------------
389
390    /// Chunk length.
391    ChunkLength,
392
393    /// Chunk extension name.
394    ChunkExtensionName,
395
396    /// Chunk extension value.
397    ChunkExtensionValue,
398
399    /// Chunk data.
400    ChunkData,
401
402    // ---------------------------------------------------------------------------------------------
403    // MULTIPART STATES
404    // ---------------------------------------------------------------------------------------------
405
406    /// Multipart data.
407    MultipartData,
408
409    // ---------------------------------------------------------------------------------------------
410    // URL ENCODED STATES
411    // ---------------------------------------------------------------------------------------------
412
413    /// URL encoded name.
414    UrlEncodedName,
415
416    /// URL encoded value.
417    UrlEncodedValue
418}