Crow  1.1
A C++ microframework for the web
Loading...
Searching...
No Matches
http_parser_merged.h
1/* merged revision: 5b951d74bd66ec9d38448e0a85b1cf8b85d97db3 */
2/* updated to : e13b274770da9b82a1085dec29182acfea72e7a7 (beyond v2.9.5) */
3/* commits not included:
4 * 091ebb87783a58b249062540bbea07de2a11e9cf
5 * 6132d1fefa03f769a3979355d1f5da0b8889cad2
6 * 7ba312397c2a6c851a4b5efe6c1603b1e1bda6ff
7 * d7675453a6c03180572f084e95eea0d02df39164
8 * dff604db203986e532e5a679bafd0e7382c6bdd9 (Might be useful to actually add [upgrade requests with a body])
9 * e01811e7f4894d7f0f7f4bd8492cccec6f6b4038 (related to above)
10 * 05525c5fde1fc562481f6ae08fa7056185325daf (also related to above)
11 * 350258965909f249f9c59823aac240313e0d0120 (cannot be implemented due to upgrade)
12 */
13
14// clang-format off
15#pragma once
16extern "C" {
17#include <stddef.h>
18#if defined(_WIN32) && !defined(__MINGW32__) && \
19 (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
20#include <BaseTsd.h>
21typedef __int8 int8_t;
22typedef unsigned __int8 uint8_t;
23typedef __int16 int16_t;
24typedef unsigned __int16 uint16_t;
25typedef __int32 int32_t;
26typedef unsigned __int32 uint32_t;
27typedef __int64 int64_t;
28typedef unsigned __int64 uint64_t;
29#elif (defined(__sun) || defined(__sun__)) && defined(__SunOS_5_9)
30#include <sys/inttypes.h>
31#else
32#include <stdint.h>
33#endif
34#include <assert.h>
35#include <ctype.h>
36#include <string.h>
37#include <limits.h>
38}
39
40#include "crow/common.h"
41namespace crow
42{
43/* Maximium header size allowed. If the macro is not defined
44 * before including this header then the default is used. To
45 * change the maximum header size, define the macro in the build
46 * environment (e.g. -DHTTP_MAX_HEADER_SIZE=<value>). To remove
47 * the effective limit on the size of the header, define the macro
48 * to a very large number (e.g. -DCROW_HTTP_MAX_HEADER_SIZE=0x7fffffff)
49 */
50#ifndef CROW_HTTP_MAX_HEADER_SIZE
51# define CROW_HTTP_MAX_HEADER_SIZE (80*1024)
52#endif
53
54typedef struct http_parser http_parser;
56
57/* Callbacks should return non-zero to indicate an error. The parser will
58 * then halt execution.
59 *
60 * The one exception is on_headers_complete. In a HTTP_RESPONSE parser
61 * returning '1' from on_headers_complete will tell the parser that it
62 * should not expect a body. This is used when receiving a response to a
63 * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding:
64 * chunked' headers that indicate the presence of a body.
65 *
66 * Returning `2` from on_headers_complete will tell parser that it should not
67 * expect neither a body nor any futher responses on this connection. This is
68 * useful for handling responses to a CONNECT request which may not contain
69 * `Upgrade` or `Connection: upgrade` headers.
70 *
71 * http_data_cb does not return data chunks. It will be called arbitrarally
72 * many times for each string. E.G. you might get 10 callbacks for "on_url"
73 * each providing just a few characters more data.
74 */
75typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
76typedef int (*http_cb) (http_parser*);
77
78
79/* Flag values for http_parser.flags field */
80enum http_connection_flags // This is basically 7 booleans placed into 1 integer. Uses 4 bytes instead of n bytes (7 currently).
81 { F_CHUNKED = 1 << 0 // 00000000 00000000 00000000 00000001
82 , F_CONNECTION_KEEP_ALIVE = 1 << 1 // 00000000 00000000 00000000 00000010
83 , F_CONNECTION_CLOSE = 1 << 2 // 00000000 00000000 00000000 00000100
84 , F_TRAILING = 1 << 3 // 00000000 00000000 00000000 00001000
85 , F_UPGRADE = 1 << 4 // 00000000 00000000 00000000 00010000
86 , F_SKIPBODY = 1 << 5 // 00000000 00000000 00000000 00100000
87 , F_CONTENTLENGTH = 1 << 6 // 00000000 00000000 00000000 01000000
88 };
89
90
91/* Map for errno-related constants
92 *
93 * The provided argument should be a macro that takes 2 arguments.
94 */
95#define CROW_HTTP_ERRNO_MAP(CROW_XX) \
96 /* No error */ \
97 CROW_XX(OK, "success") \
98 \
99 /* Callback-related errors */ \
100 CROW_XX(CB_message_begin, "the on_message_begin callback failed") \
101 CROW_XX(CB_method, "the on_method callback failed") \
102 CROW_XX(CB_url, "the \"on_url\" callback failed") \
103 CROW_XX(CB_header_field, "the \"on_header_field\" callback failed") \
104 CROW_XX(CB_header_value, "the \"on_header_value\" callback failed") \
105 CROW_XX(CB_headers_complete, "the \"on_headers_complete\" callback failed") \
106 CROW_XX(CB_body, "the \"on_body\" callback failed") \
107 CROW_XX(CB_message_complete, "the \"on_message_complete\" callback failed") \
108 CROW_XX(CB_status, "the \"on_status\" callback failed") \
109 \
110 /* Parsing-related errors */ \
111 CROW_XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
112 CROW_XX(HEADER_OVERFLOW, "too many header bytes seen; overflow detected") \
113 CROW_XX(CLOSED_CONNECTION, "data received after completed connection: close message") \
114 CROW_XX(INVALID_VERSION, "invalid HTTP version") \
115 CROW_XX(INVALID_STATUS, "invalid HTTP status code") \
116 CROW_XX(INVALID_METHOD, "invalid HTTP method") \
117 CROW_XX(INVALID_URL, "invalid URL") \
118 CROW_XX(INVALID_HOST, "invalid host") \
119 CROW_XX(INVALID_PORT, "invalid port") \
120 CROW_XX(INVALID_PATH, "invalid path") \
121 CROW_XX(INVALID_QUERY_STRING, "invalid query string") \
122 CROW_XX(INVALID_FRAGMENT, "invalid fragment") \
123 CROW_XX(LF_EXPECTED, "LF character expected") \
124 CROW_XX(INVALID_HEADER_TOKEN, "invalid character in header") \
125 CROW_XX(INVALID_CONTENT_LENGTH, "invalid character in content-length header") \
126 CROW_XX(UNEXPECTED_CONTENT_LENGTH, "unexpected content-length header") \
127 CROW_XX(INVALID_CHUNK_SIZE, "invalid character in chunk size header") \
128 CROW_XX(INVALID_CONSTANT, "invalid constant string") \
129 CROW_XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state") \
130 CROW_XX(STRICT, "strict mode assertion failed") \
131 CROW_XX(UNKNOWN, "an unknown error occurred") \
132 CROW_XX(INVALID_TRANSFER_ENCODING, "request has invalid transfer-encoding") \
133
134
135/* Define CHPE_* values for each errno value above */
136#define CROW_HTTP_ERRNO_GEN(n, s) CHPE_##n,
137enum http_errno {
138 CROW_HTTP_ERRNO_MAP(CROW_HTTP_ERRNO_GEN)
139};
140#undef CROW_HTTP_ERRNO_GEN
141
142
143/* Get an http_errno value from an http_parser */
144#define CROW_HTTP_PARSER_ERRNO(p) ((enum http_errno)(p)->http_errno)
145
146
148 {
149 /** PRIVATE **/
150 unsigned int flags : 7; /* F_* values from 'flags' enum; semi-public */
151 unsigned int state : 8; /* enum state from http_parser.c */
152 unsigned int header_state : 7; /* enum header_state from http_parser.c */
153 unsigned int index : 5; /* index into current matcher */
154 unsigned int uses_transfer_encoding : 1; /* Transfer-Encoding header is present */
155 unsigned int allow_chunked_length : 1; /* Allow headers with both `Content-Length` and `Transfer-Encoding: chunked` set */
156 unsigned int lenient_http_headers : 1;
157
158 uint32_t nread; /* # bytes read in various scenarios */
159 uint64_t content_length; /* # bytes in body. `(uint64_t) -1` (all bits one) if no Content-Length header. */
160
161 /** READ-ONLY **/
162 unsigned char http_major;
163 unsigned char http_minor;
164 unsigned int method : 8; /* requests only */
165 unsigned int http_errno : 7;
166
167 /* 1 = Upgrade header was present and the parser has exited because of that.
168 * 0 = No upgrade header present.
169 * Should be checked when http_parser_execute() returns in addition to
170 * error checking.
171 */
172 unsigned int upgrade : 1;
173
174 /** PUBLIC **/
175 void* data; /* A pointer to get hook to the "connection" or "socket" object */
176 };
177
178
180 {
181 http_cb on_message_begin;
182 http_cb on_method;
183 http_data_cb on_url;
184 http_data_cb on_header_field;
185 http_data_cb on_header_value;
186 http_cb on_headers_complete;
187 http_data_cb on_body;
188 http_cb on_message_complete;
189 };
190
191
192
193// SOURCE (.c) CODE
194static uint32_t max_header_size = CROW_HTTP_MAX_HEADER_SIZE;
195
196#ifndef CROW_ULLONG_MAX
197# define CROW_ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */
198#endif
199
200#ifndef CROW_MIN
201# define CROW_MIN(a,b) ((a) < (b) ? (a) : (b))
202#endif
203
204#ifndef CROW_ARRAY_SIZE
205# define CROW_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
206#endif
207
208#ifndef CROW_BIT_AT
209# define CROW_BIT_AT(a, i) \
210 (!!((unsigned int) (a)[(unsigned int) (i) >> 3] & \
211 (1 << ((unsigned int) (i) & 7))))
212#endif
213
214#define CROW_SET_ERRNO(e) \
215do { \
216 parser->nread = nread; \
217 parser->http_errno = (e); \
218} while(0)
219
220/* Run the notify callback FOR, returning ER if it fails */
221#define CROW_CALLBACK_NOTIFY_(FOR, ER) \
222do { \
223 assert(CROW_HTTP_PARSER_ERRNO(parser) == CHPE_OK); \
224 \
225 if (CROW_LIKELY(settings->on_##FOR)) { \
226 if (CROW_UNLIKELY(0 != settings->on_##FOR(parser))) { \
227 CROW_SET_ERRNO(CHPE_CB_##FOR); \
228 } \
229 \
230 /* We either errored above or got paused; get out */ \
231 if (CROW_UNLIKELY(CROW_HTTP_PARSER_ERRNO(parser) != CHPE_OK)) { \
232 return (ER); \
233 } \
234 } \
235} while (0)
236
237/* Run the notify callback FOR and consume the current byte */
238#define CROW_CALLBACK_NOTIFY(FOR) CROW_CALLBACK_NOTIFY_(FOR, p - data + 1)
239
240/* Run the notify callback FOR and don't consume the current byte */
241#define CROW_CALLBACK_NOTIFY_NOADVANCE(FOR) CROW_CALLBACK_NOTIFY_(FOR, p - data)
242
243/* Run data callback FOR with LEN bytes, returning ER if it fails */
244#define CROW_CALLBACK_DATA_(FOR, LEN, ER) \
245do { \
246 assert(CROW_HTTP_PARSER_ERRNO(parser) == CHPE_OK); \
247 \
248 if (FOR##_mark) { \
249 if (CROW_LIKELY(settings->on_##FOR)) { \
250 if (CROW_UNLIKELY(0 != \
251 settings->on_##FOR(parser, FOR##_mark, (LEN)))) { \
252 CROW_SET_ERRNO(CHPE_CB_##FOR); \
253 } \
254 \
255 /* We either errored above or got paused; get out */ \
256 if (CROW_UNLIKELY(CROW_HTTP_PARSER_ERRNO(parser) != CHPE_OK)) {\
257 return (ER); \
258 } \
259 } \
260 FOR##_mark = NULL; \
261 } \
262} while (0)
263
264/* Run the data callback FOR and consume the current byte */
265#define CROW_CALLBACK_DATA(FOR) \
266 CROW_CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1)
267
268/* Run the data callback FOR and don't consume the current byte */
269#define CROW_CALLBACK_DATA_NOADVANCE(FOR) \
270 CROW_CALLBACK_DATA_(FOR, p - FOR##_mark, p - data)
271
272/* Set the mark FOR; non-destructive if mark is already set */
273#define CROW_MARK(FOR) \
274do { \
275 if (!FOR##_mark) { \
276 FOR##_mark = p; \
277 } \
278} while (0)
279
280/* Don't allow the total size of the HTTP headers (including the status
281 * line) to exceed max_header_size. This check is here to protect
282 * embedders against denial-of-service attacks where the attacker feeds
283 * us a never-ending header that the embedder keeps buffering.
284 *
285 * This check is arguably the responsibility of embedders but we're doing
286 * it on the embedder's behalf because most won't bother and this way we
287 * make the web a little safer. max_header_size is still far bigger
288 * than any reasonable request or response so this should never affect
289 * day-to-day operation.
290 */
291#define CROW_COUNT_HEADER_SIZE(V) \
292do { \
293 nread += (uint32_t)(V); \
294 if (CROW_UNLIKELY(nread > max_header_size)) { \
295 CROW_SET_ERRNO(CHPE_HEADER_OVERFLOW); \
296 goto error; \
297 } \
298} while (0)
299#define CROW_REEXECUTE() \
300 goto reexecute; \
301
302#define CROW_PROXY_CONNECTION "proxy-connection"
303#define CROW_CONNECTION "connection"
304#define CROW_CONTENT_LENGTH "content-length"
305#define CROW_TRANSFER_ENCODING "transfer-encoding"
306#define CROW_UPGRADE "upgrade"
307#define CROW_CHUNKED "chunked"
308#define CROW_KEEP_ALIVE "keep-alive"
309#define CROW_CLOSE "close"
310
311
312
313 enum state
314 {
315 s_dead = 1 /* important that this is > 0 */
316
317 ,
318 s_start_req
319
320 ,
321 s_req_method,
322 s_req_spaces_before_url,
323 s_req_schema,
324 s_req_schema_slash,
325 s_req_schema_slash_slash,
326 s_req_server_start,
327 s_req_server, // }
328 s_req_server_with_at, // |
329 s_req_path, // | The parser recognizes how to switch between these states,
330 s_req_query_string_start, // | however it doesn't process them any differently.
331 s_req_query_string, // }
332 s_req_http_start,
333 s_req_http_H,
334 s_req_http_HT,
335 s_req_http_HTT,
336 s_req_http_HTTP,
337 s_req_http_I,
338 s_req_http_IC,
339 s_req_http_major,
340 s_req_http_dot,
341 s_req_http_minor,
342 s_req_http_end,
343 s_req_line_almost_done
344
345 ,
346 s_header_field_start,
347 s_header_field,
348 s_header_value_discard_ws,
349 s_header_value_discard_ws_almost_done,
350 s_header_value_discard_lws,
351 s_header_value_start,
352 s_header_value,
353 s_header_value_lws
354
355 ,
356 s_header_almost_done
357
358 ,
359 s_chunk_size_start,
360 s_chunk_size,
361 s_chunk_parameters,
362 s_chunk_size_almost_done
363
364 ,
365 s_headers_almost_done,
366 s_headers_done
367
368 /* Important: 's_headers_done' must be the last 'header' state. All
369 * states beyond this must be 'body' states. It is used for overflow
370 * checking. See the CROW_PARSING_HEADER() macro.
371 */
372
373 ,
374 s_chunk_data,
375 s_chunk_data_almost_done,
376 s_chunk_data_done
377
378 ,
379 s_body_identity,
380 s_body_identity_eof
381
382 ,
383 s_message_done
384 };
385
386
387#define CROW_PARSING_HEADER(state) (state <= s_headers_done)
388
389
390enum header_states
391 { h_general = 0
392 , h_C
393 , h_CO
394 , h_CON
395
396 , h_matching_connection
397 , h_matching_proxy_connection
398 , h_matching_content_length
399 , h_matching_transfer_encoding
400 , h_matching_upgrade
401
402 , h_connection
403 , h_content_length
404 , h_content_length_num
405 , h_content_length_ws
406 , h_transfer_encoding
407 , h_upgrade
408
409 , h_matching_transfer_encoding_token_start
410 , h_matching_transfer_encoding_chunked
411 , h_matching_transfer_encoding_token
412
413 , h_matching_connection_keep_alive
414 , h_matching_connection_close
415
416 , h_transfer_encoding_chunked
417 , h_connection_keep_alive
418 , h_connection_close
419 };
420
421enum http_host_state
422 {
423 s_http_host_dead = 1
424 , s_http_userinfo_start
425 , s_http_userinfo
426 , s_http_host_start
427 , s_http_host_v6_start
428 , s_http_host
429 , s_http_host_v6
430 , s_http_host_v6_end
431 , s_http_host_v6_zone_start
432 , s_http_host_v6_zone
433 , s_http_host_port_start
434 , s_http_host_port
435};
436
437/* Macros for character classes; depends on strict-mode */
438#define CROW_LOWER(c) (unsigned char)(c | 0x20)
439#define CROW_IS_ALPHA(c) (CROW_LOWER(c) >= 'a' && CROW_LOWER(c) <= 'z')
440#define CROW_IS_NUM(c) ((c) >= '0' && (c) <= '9')
441#define CROW_IS_ALPHANUM(c) (CROW_IS_ALPHA(c) || CROW_IS_NUM(c))
442//#define CROW_IS_HEX(c) (CROW_IS_NUM(c) || (CROW_LOWER(c) >= 'a' && CROW_LOWER(c) <= 'f'))
443#define CROW_IS_MARK(c) ((c) == '-' || (c) == '_' || (c) == '.' || \
444 (c) == '!' || (c) == '~' || (c) == '*' || (c) == '\'' || (c) == '(' || \
445 (c) == ')')
446#define CROW_IS_USERINFO_CHAR(c) (CROW_IS_ALPHANUM(c) || CROW_IS_MARK(c) || (c) == '%' || \
447 (c) == ';' || (c) == ':' || (c) == '&' || (c) == '=' || (c) == '+' || \
448 (c) == '$' || (c) == ',')
449
450#define CROW_TOKEN(c) (tokens[(unsigned char)c])
451#define CROW_IS_URL_CHAR(c) (CROW_BIT_AT(normal_url_char, (unsigned char)c))
452//#define CROW_IS_HOST_CHAR(c) (CROW_IS_ALPHANUM(c) || (c) == '.' || (c) == '-')
453
454 /**
455 * Verify that a char is a valid visible (printable) US-ASCII
456 * character or %x80-FF
457 **/
458#define CROW_IS_HEADER_CHAR(ch) \
459 (ch == cr || ch == lf || ch == 9 || ((unsigned char)ch > 31 && ch != 127))
460
461#define CROW_start_state s_start_req
462
463# define CROW_STRICT_CHECK(cond) \
464do { \
465 if (cond) { \
466 CROW_SET_ERRNO(CHPE_STRICT); \
467 goto error; \
468 } \
469} while (0)
470#define CROW_NEW_MESSAGE() (CROW_start_state)
471
472/* Our URL parser.
473 *
474 * This is designed to be shared by http_parser_execute() for URL validation,
475 * hence it has a state transition + byte-for-byte interface. In addition, it
476 * is meant to be embedded in http_parser_parse_url(), which does the dirty
477 * work of turning state transitions URL components for its API.
478 *
479 * This function should only be invoked with non-space characters. It is
480 * assumed that the caller cares about (and can detect) the transition between
481 * URL and non-URL states by looking for these.
482 */
483inline enum state
484parse_url_char(enum state s, const char ch)
485{
486# define CROW_T(v) 0
487
488
489static const uint8_t normal_url_char[32] = {
490/* 0 nul 1 soh 2 stx 3 etx 4 eot 5 enq 6 ack 7 bel */
491 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0,
492/* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */
493 0 |CROW_T(2)| 0 | 0 |CROW_T(16)| 0 | 0 | 0,
494/* 16 dle 17 dc1 18 dc2 19 dc3 20 dc4 21 nak 22 syn 23 etb */
495 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0,
496/* 24 can 25 em 26 sub 27 esc 28 fs 29 gs 30 rs 31 us */
497 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0,
498/* 32 sp 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' */
499 0 | 2 | 4 | 0 | 16 | 32 | 64 | 128,
500/* 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / */
501 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
502/* 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 */
503 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
504/* 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? */
505 1 | 2 | 4 | 8 | 16 | 32 | 64 | 0,
506/* 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G */
507 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
508/* 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O */
509 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
510/* 80 P 81 Q 82 R 83 S 84 CROW_T 85 U 86 V 87 W */
511 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
512/* 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ^ 95 _ */
513 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
514/* 96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g */
515 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
516/* 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o */
517 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
518/* 112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w */
519 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128,
520/* 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 del */
521 1 | 2 | 4 | 8 | 16 | 32 | 64 | 0, };
522
523#undef CROW_T
524
525 if (ch == ' ' || ch == '\r' || ch == '\n') {
526 return s_dead;
527 }
528 if (ch == '\t' || ch == '\f') {
529 return s_dead;
530 }
531
532 switch (s) {
533 case s_req_spaces_before_url:
534 /* Proxied requests are followed by scheme of an absolute URI (alpha).
535 * All methods except CONNECT are followed by '/' or '*'.
536 */
537
538 if (ch == '/' || ch == '*') {
539 return s_req_path;
540 }
541
542 if (CROW_IS_ALPHA(ch)) {
543 return s_req_schema;
544 }
545
546 break;
547
548 case s_req_schema:
549 if (CROW_IS_ALPHA(ch)) {
550 return s;
551 }
552
553 if (ch == ':') {
554 return s_req_schema_slash;
555 }
556
557 break;
558
559 case s_req_schema_slash:
560 if (ch == '/') {
561 return s_req_schema_slash_slash;
562 }
563
564 break;
565
566 case s_req_schema_slash_slash:
567 if (ch == '/') {
568 return s_req_server_start;
569 }
570
571 break;
572
573 case s_req_server_with_at:
574 if (ch == '@') {
575 return s_dead;
576 }
577
578 /* fall through */
579 case s_req_server_start:
580 case s_req_server:
581 if (ch == '/') {
582 return s_req_path;
583 }
584
585 if (ch == '?') {
586 return s_req_query_string_start;
587 }
588
589 if (ch == '@') {
590 return s_req_server_with_at;
591 }
592
593 if (CROW_IS_USERINFO_CHAR(ch) || ch == '[' || ch == ']') {
594 return s_req_server;
595 }
596
597 break;
598
599 case s_req_path:
600 if (CROW_IS_URL_CHAR(ch)) {
601 return s;
602 }
603 else if (ch == '?')
604 {
605 return s_req_query_string_start;
606 }
607
608 break;
609
610 case s_req_query_string_start:
611 case s_req_query_string:
612 if (CROW_IS_URL_CHAR(ch)) {
613 return s_req_query_string;
614 }
615 else if (ch == '?')
616 {
617 return s_req_query_string;
618 }
619
620 break;
621
622 default:
623 break;
624 }
625
626 /* We should never fall out of the switch above unless there's an error */
627 return s_dead;
628}
629
630inline size_t http_parser_execute (http_parser *parser,
631 const http_parser_settings *settings,
632 const char *data,
633 size_t len)
634{
635
636/* Tokens as defined by rfc 2616. Also lowercases them.
637 * token = 1*<any CHAR except CTLs or separators>
638 * separators = "(" | ")" | "<" | ">" | "@"
639 * | "," | ";" | ":" | "\" | <">
640 * | "/" | "[" | "]" | "?" | "="
641 * | "{" | "}" | SP | HT
642 */
643static const char tokens[256] = {
644/* 0 nul 1 soh 2 stx 3 etx 4 eot 5 enq 6 ack 7 bel */
645 0, 0, 0, 0, 0, 0, 0, 0,
646/* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */
647 0, 0, 0, 0, 0, 0, 0, 0,
648/* 16 dle 17 dc1 18 dc2 19 dc3 20 dc4 21 nak 22 syn 23 etb */
649 0, 0, 0, 0, 0, 0, 0, 0,
650/* 24 can 25 em 26 sub 27 esc 28 fs 29 gs 30 rs 31 us */
651 0, 0, 0, 0, 0, 0, 0, 0,
652/* 32 sp 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' */
653 0, '!', 0, '#', '$', '%', '&', '\'',
654/* 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / */
655 0, 0, '*', '+', 0, '-', '.', 0,
656/* 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 */
657 '0', '1', '2', '3', '4', '5', '6', '7',
658/* 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? */
659 '8', '9', 0, 0, 0, 0, 0, 0,
660/* 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G */
661 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
662/* 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O */
663 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
664/* 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W */
665 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
666/* 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ^ 95 _ */
667 'x', 'y', 'z', 0, 0, 0, '^', '_',
668/* 96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g */
669 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
670/* 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o */
671 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
672/* 112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w */
673 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
674/* 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 del */
675 'x', 'y', 'z', 0, '|', 0, '~', 0 };
676
677
678static const int8_t unhex[256] =
679 {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
680 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
681 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
682 , 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1
683 ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
684 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
685 ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1
686 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
687 };
688
689
690
691 char c, ch;
692 int8_t unhex_val;
693 const char *p = data;
694 const char *header_field_mark = 0;
695 const char *header_value_mark = 0;
696 const char *url_mark = 0;
697 const char *body_mark = 0;
698 const unsigned int lenient = parser->lenient_http_headers;
699 const unsigned int allow_chunked_length = parser->allow_chunked_length;
700
701 uint32_t nread = parser->nread;
702
703 /* We're in an error state. Don't bother doing anything. */
704 if (CROW_HTTP_PARSER_ERRNO(parser) != CHPE_OK) {
705 return 0;
706 }
707
708 if (len == 0) {
709 switch (parser->state) {
710 case s_body_identity_eof:
711 /* Use of CROW_CALLBACK_NOTIFY() here would erroneously return 1 byte read if we got paused. */
712 CROW_CALLBACK_NOTIFY_NOADVANCE(message_complete);
713 return 0;
714
715 case s_dead:
716 case s_start_req:
717 return 0;
718
719 default:
720 CROW_SET_ERRNO(CHPE_INVALID_EOF_STATE);
721 return 1;
722 }
723 }
724
725
726 if (parser->state == s_header_field)
727 header_field_mark = data;
728 if (parser->state == s_header_value)
729 header_value_mark = data;
730 switch (parser->state) {
731 case s_req_path:
732 case s_req_schema:
733 case s_req_schema_slash:
734 case s_req_schema_slash_slash:
735 case s_req_server_start:
736 case s_req_server:
737 case s_req_server_with_at:
738 case s_req_query_string_start:
739 case s_req_query_string:
740 url_mark = data;
741 break;
742 default:
743 break;
744 }
745
746 for (p=data; p != data + len; p++) {
747 ch = *p;
748
749 if (CROW_PARSING_HEADER(parser->state))
750 CROW_COUNT_HEADER_SIZE(1);
751
752reexecute:
753 switch (parser->state) {
754
755 case s_dead:
756 /* this state is used after a 'Connection: close' message
757 * the parser will error out if it reads another message
758 */
759 if (CROW_LIKELY(ch == cr || ch == lf))
760 break;
761
762 CROW_SET_ERRNO(CHPE_CLOSED_CONNECTION);
763 goto error;
764
765 case s_start_req:
766 {
767 if (ch == cr || ch == lf)
768 break;
769 parser->flags = 0;
770 parser->uses_transfer_encoding = 0;
771 parser->content_length = CROW_ULLONG_MAX;
772
773 if (CROW_UNLIKELY(!CROW_IS_ALPHA(ch))) {
774 CROW_SET_ERRNO(CHPE_INVALID_METHOD);
775 goto error;
776 }
777
778 parser->method = 0;
779 parser->index = 1;
780 switch (ch) {
781 case 'A': parser->method = (unsigned)HTTPMethod::Acl; break;
782 case 'B': parser->method = (unsigned)HTTPMethod::Bind; break;
783 case 'C': parser->method = (unsigned)HTTPMethod::Connect; /* or COPY, CHECKOUT */ break;
784 case 'D': parser->method = (unsigned)HTTPMethod::Delete; break;
785 case 'G': parser->method = (unsigned)HTTPMethod::Get; break;
786 case 'H': parser->method = (unsigned)HTTPMethod::Head; break;
787 case 'L': parser->method = (unsigned)HTTPMethod::Lock; /* or LINK */ break;
788 case 'M': parser->method = (unsigned)HTTPMethod::MkCol; /* or MOVE, MKACTIVITY, MERGE, M-SEARCH, MKCALENDAR */ break;
789 case 'N': parser->method = (unsigned)HTTPMethod::Notify; break;
790 case 'O': parser->method = (unsigned)HTTPMethod::Options; break;
791 case 'P': parser->method = (unsigned)HTTPMethod::Post; /* or PROPFIND|PROPPATCH|PUT|PATCH|PURGE */ break;
792 case 'R': parser->method = (unsigned)HTTPMethod::Report; /* or REBIND */ break;
793 case 'S': parser->method = (unsigned)HTTPMethod::Subscribe; /* or SEARCH, SOURCE */ break;
794 case 'T': parser->method = (unsigned)HTTPMethod::Trace; break;
795 case 'U': parser->method = (unsigned)HTTPMethod::Unlock; /* or UNSUBSCRIBE, UNBIND, UNLINK */ break;
796 default:
797 CROW_SET_ERRNO(CHPE_INVALID_METHOD);
798 goto error;
799 }
800 parser->state = s_req_method;
801
802 CROW_CALLBACK_NOTIFY(message_begin);
803
804 break;
805 }
806
807 case s_req_method:
808 {
809 const char *matcher;
810 if (CROW_UNLIKELY(ch == '\0')) {
811 CROW_SET_ERRNO(CHPE_INVALID_METHOD);
812 goto error;
813 }
814
815 matcher = method_strings[parser->method];
816 if (ch == ' ' && matcher[parser->index] == '\0') {
817 parser->state = s_req_spaces_before_url;
818 } else if (ch == matcher[parser->index]) {
819 ; /* nada */
820 } else if ((ch >= 'A' && ch <= 'Z') || ch == '-') {
821
822 switch (parser->method << 16 | parser->index << 8 | ch) {
823#define CROW_XX(meth, pos, ch, new_meth) \
824 case ((unsigned)HTTPMethod::meth << 16 | pos << 8 | ch): \
825 parser->method = (unsigned)HTTPMethod::new_meth; break;
826
827 CROW_XX(Post, 1, 'U', Put)
828 CROW_XX(Post, 1, 'A', Patch)
829 CROW_XX(Post, 1, 'R', Propfind)
830 CROW_XX(Put, 2, 'R', Purge)
831 CROW_XX(Connect, 1, 'H', Checkout)
832 CROW_XX(Connect, 2, 'P', Copy)
833 CROW_XX(MkCol, 1, 'O', Move)
834 CROW_XX(MkCol, 1, 'E', Merge)
835 CROW_XX(MkCol, 1, '-', MSearch)
836 CROW_XX(MkCol, 2, 'A', MkActivity)
837 CROW_XX(MkCol, 3, 'A', MkCalendar)
838 CROW_XX(Subscribe, 1, 'E', Search)
839 CROW_XX(Subscribe, 1, 'O', Source)
840 CROW_XX(Report, 2, 'B', Rebind)
841 CROW_XX(Propfind, 4, 'P', Proppatch)
842 CROW_XX(Lock, 1, 'I', Link)
843 CROW_XX(Unlock, 2, 'S', Unsubscribe)
844 CROW_XX(Unlock, 2, 'B', Unbind)
845 CROW_XX(Unlock, 3, 'I', Unlink)
846#undef CROW_XX
847 default:
848 CROW_SET_ERRNO(CHPE_INVALID_METHOD);
849 goto error;
850 }
851 } else {
852 CROW_SET_ERRNO(CHPE_INVALID_METHOD);
853 goto error;
854 }
855
856 CROW_CALLBACK_NOTIFY_NOADVANCE(method);
857
858 ++parser->index;
859 break;
860 }
861
862 case s_req_spaces_before_url:
863 {
864 if (ch == ' ') break;
865
866 CROW_MARK(url);
867 if (parser->method == (unsigned)HTTPMethod::Connect) {
868 parser->state = s_req_server_start;
869 }
870
871 parser->state = parse_url_char(static_cast<state>(parser->state), ch);
872 if (CROW_UNLIKELY(parser->state == s_dead)) {
873 CROW_SET_ERRNO(CHPE_INVALID_URL);
874 goto error;
875 }
876
877 break;
878 }
879
880 case s_req_schema:
881 case s_req_schema_slash:
882 case s_req_schema_slash_slash:
883 case s_req_server_start:
884 {
885 switch (ch) {
886 /* No whitespace allowed here */
887 case ' ':
888 case cr:
889 case lf:
890 CROW_SET_ERRNO(CHPE_INVALID_URL);
891 goto error;
892 default:
893 parser->state = parse_url_char(static_cast<state>(parser->state), ch);
894 if (CROW_UNLIKELY(parser->state == s_dead)) {
895 CROW_SET_ERRNO(CHPE_INVALID_URL);
896 goto error;
897 }
898 }
899
900 break;
901 }
902
903 case s_req_server:
904 case s_req_server_with_at:
905 case s_req_path:
906 case s_req_query_string_start:
907 case s_req_query_string:
908 {
909 switch (ch) {
910 case ' ':
911 parser->state = s_req_http_start;
912 CROW_CALLBACK_DATA(url);
913 break;
914 case cr: // No space after URL means no HTTP version. Which means the request is using HTTP/0.9
915 case lf:
916 if (CROW_UNLIKELY(parser->method != (unsigned)HTTPMethod::Get)) // HTTP/0.9 doesn't define any method other than GET
917 {
918 parser->state = s_dead;
919 CROW_SET_ERRNO(CHPE_INVALID_VERSION);
920 goto error;
921 }
922 parser->http_major = 0;
923 parser->http_minor = 9;
924 parser->state = (ch == cr) ?
925 s_req_line_almost_done :
926 s_header_field_start;
927 CROW_CALLBACK_DATA(url);
928 break;
929 default:
930 parser->state = parse_url_char(static_cast<state>(parser->state), ch);
931 if (CROW_UNLIKELY(parser->state == s_dead)) {
932 CROW_SET_ERRNO(CHPE_INVALID_URL);
933 goto error;
934 }
935 }
936 break;
937 }
938
939 case s_req_http_start:
940 switch (ch) {
941 case ' ':
942 break;
943 case 'H':
944 parser->state = s_req_http_H;
945 break;
946 case 'I':
947 if (parser->method == (unsigned)HTTPMethod::Source) {
948 parser->state = s_req_http_I;
949 break;
950 }
951 /* fall through */
952 default:
953 CROW_SET_ERRNO(CHPE_INVALID_CONSTANT);
954 goto error;
955 }
956 break;
957
958 case s_req_http_H:
959 CROW_STRICT_CHECK(ch != 'T');
960 parser->state = s_req_http_HT;
961 break;
962
963 case s_req_http_HT:
964 CROW_STRICT_CHECK(ch != 'T');
965 parser->state = s_req_http_HTT;
966 break;
967
968 case s_req_http_HTT:
969 CROW_STRICT_CHECK(ch != 'P');
970 parser->state = s_req_http_HTTP;
971 break;
972
973 case s_req_http_I:
974 CROW_STRICT_CHECK(ch != 'C');
975 parser->state = s_req_http_IC;
976 break;
977
978 case s_req_http_IC:
979 CROW_STRICT_CHECK(ch != 'E');
980 parser->state = s_req_http_HTTP; /* Treat "ICE" as "HTTP". */
981 break;
982
983 case s_req_http_HTTP:
984 CROW_STRICT_CHECK(ch != '/');
985 parser->state = s_req_http_major;
986 break;
987
988 /* dot */
989 case s_req_http_major:
990 if (CROW_UNLIKELY(!CROW_IS_NUM(ch))) {
991 CROW_SET_ERRNO(CHPE_INVALID_VERSION);
992 goto error;
993 }
994
995 parser->http_major = ch - '0';
996 parser->state = s_req_http_dot;
997 break;
998
999 case s_req_http_dot:
1000 {
1001 if (CROW_UNLIKELY(ch != '.')) {
1002 CROW_SET_ERRNO(CHPE_INVALID_VERSION);
1003 goto error;
1004 }
1005
1006 parser->state = s_req_http_minor;
1007 break;
1008 }
1009
1010 /* minor HTTP version */
1011 case s_req_http_minor:
1012 if (CROW_UNLIKELY(!CROW_IS_NUM(ch))) {
1013 CROW_SET_ERRNO(CHPE_INVALID_VERSION);
1014 goto error;
1015 }
1016
1017 parser->http_minor = ch - '0';
1018 parser->state = s_req_http_end;
1019 break;
1020
1021 /* end of request line */
1022 case s_req_http_end:
1023 {
1024 if (ch == cr) {
1025 parser->state = s_req_line_almost_done;
1026 break;
1027 }
1028
1029 if (ch == lf) {
1030 parser->state = s_header_field_start;
1031 break;
1032 }
1033
1034 CROW_SET_ERRNO(CHPE_INVALID_VERSION);
1035 goto error;
1036 break;
1037 }
1038
1039 /* end of request line */
1040 case s_req_line_almost_done:
1041 {
1042 if (CROW_UNLIKELY(ch != lf)) {
1043 CROW_SET_ERRNO(CHPE_LF_EXPECTED);
1044 goto error;
1045 }
1046
1047 parser->state = s_header_field_start;
1048 break;
1049 }
1050
1051 case s_header_field_start:
1052 {
1053 if (ch == cr) {
1054 parser->state = s_headers_almost_done;
1055 break;
1056 }
1057
1058 if (ch == lf) {
1059 /* they might be just sending \n instead of \r\n so this would be
1060 * the second \n to denote the end of headers*/
1061 parser->state = s_headers_almost_done;
1062 CROW_REEXECUTE();
1063 }
1064
1065 c = CROW_TOKEN(ch);
1066
1067 if (CROW_UNLIKELY(!c)) {
1068 CROW_SET_ERRNO(CHPE_INVALID_HEADER_TOKEN);
1069 goto error;
1070 }
1071
1072 CROW_MARK(header_field);
1073
1074 parser->index = 0;
1075 parser->state = s_header_field;
1076
1077 switch (c) {
1078 case 'c':
1079 parser->header_state = h_C;
1080 break;
1081
1082 case 'p':
1083 parser->header_state = h_matching_proxy_connection;
1084 break;
1085
1086 case 't':
1087 parser->header_state = h_matching_transfer_encoding;
1088 break;
1089
1090 case 'u':
1091 parser->header_state = h_matching_upgrade;
1092 break;
1093
1094 default:
1095 parser->header_state = h_general;
1096 break;
1097 }
1098 break;
1099 }
1100
1101 case s_header_field:
1102 {
1103 const char* start = p;
1104 for (; p != data + len; p++) {
1105 ch = *p;
1106 c = CROW_TOKEN(ch);
1107
1108 if (!c)
1109 break;
1110
1111 switch (parser->header_state) {
1112 case h_general: {
1113 size_t left = data + len - p;
1114 const char* pe = p + CROW_MIN(left, max_header_size);
1115 while (p+1 < pe && CROW_TOKEN(p[1])) {
1116 p++;
1117 }
1118 break;
1119 }
1120
1121 case h_C:
1122 parser->index++;
1123 parser->header_state = (c == 'o' ? h_CO : h_general);
1124 break;
1125
1126 case h_CO:
1127 parser->index++;
1128 parser->header_state = (c == 'n' ? h_CON : h_general);
1129 break;
1130
1131 case h_CON:
1132 parser->index++;
1133 switch (c) {
1134 case 'n':
1135 parser->header_state = h_matching_connection;
1136 break;
1137 case 't':
1138 parser->header_state = h_matching_content_length;
1139 break;
1140 default:
1141 parser->header_state = h_general;
1142 break;
1143 }
1144 break;
1145
1146 /* connection */
1147
1148 case h_matching_connection:
1149 parser->index++;
1150 if (parser->index > sizeof(CROW_CONNECTION)-1 || c != CROW_CONNECTION[parser->index]) {
1151 parser->header_state = h_general;
1152 } else if (parser->index == sizeof(CROW_CONNECTION)-2) {
1153 parser->header_state = h_connection;
1154 }
1155 break;
1156
1157 /* proxy-connection */
1158
1159 case h_matching_proxy_connection:
1160 parser->index++;
1161 if (parser->index > sizeof(CROW_PROXY_CONNECTION)-1 || c != CROW_PROXY_CONNECTION[parser->index]) {
1162 parser->header_state = h_general;
1163 } else if (parser->index == sizeof(CROW_PROXY_CONNECTION)-2) {
1164 parser->header_state = h_connection;
1165 }
1166 break;
1167
1168 /* content-length */
1169
1170 case h_matching_content_length:
1171 parser->index++;
1172 if (parser->index > sizeof(CROW_CONTENT_LENGTH)-1 || c != CROW_CONTENT_LENGTH[parser->index]) {
1173 parser->header_state = h_general;
1174 } else if (parser->index == sizeof(CROW_CONTENT_LENGTH)-2) {
1175 parser->header_state = h_content_length;
1176 }
1177 break;
1178
1179 /* transfer-encoding */
1180
1181 case h_matching_transfer_encoding:
1182 parser->index++;
1183 if (parser->index > sizeof(CROW_TRANSFER_ENCODING)-1 || c != CROW_TRANSFER_ENCODING[parser->index]) {
1184 parser->header_state = h_general;
1185 } else if (parser->index == sizeof(CROW_TRANSFER_ENCODING)-2) {
1186 parser->header_state = h_transfer_encoding;
1187 parser->uses_transfer_encoding = 1;
1188 }
1189 break;
1190
1191 /* upgrade */
1192
1193 case h_matching_upgrade:
1194 parser->index++;
1195 if (parser->index > sizeof(CROW_UPGRADE)-1 || c != CROW_UPGRADE[parser->index]) {
1196 parser->header_state = h_general;
1197 } else if (parser->index == sizeof(CROW_UPGRADE)-2) {
1198 parser->header_state = h_upgrade;
1199 }
1200 break;
1201
1202 case h_connection:
1203 case h_content_length:
1204 case h_transfer_encoding:
1205 case h_upgrade:
1206 if (ch != ' ') parser->header_state = h_general;
1207 break;
1208
1209 default:
1210 assert(0 && "Unknown header_state");
1211 break;
1212 }
1213 }
1214
1215 if (p == data + len) {
1216 --p;
1217 CROW_COUNT_HEADER_SIZE(p - start);
1218 break;
1219 }
1220
1221 CROW_COUNT_HEADER_SIZE(p - start);
1222
1223 if (ch == ':') {
1224 parser->state = s_header_value_discard_ws;
1225 CROW_CALLBACK_DATA(header_field);
1226 break;
1227 }
1228/* RFC-7230 Sec 3.2.4 expressly forbids line-folding in header field-names.
1229 if (ch == cr) {
1230 parser->state = s_header_almost_done;
1231 CROW_CALLBACK_DATA(header_field);
1232 break;
1233 }
1234
1235 if (ch == lf) {
1236 parser->state = s_header_field_start;
1237 CROW_CALLBACK_DATA(header_field);
1238 break;
1239 }
1240*/
1241 CROW_SET_ERRNO(CHPE_INVALID_HEADER_TOKEN);
1242 goto error;
1243 }
1244
1245 case s_header_value_discard_ws:
1246 if (ch == ' ' || ch == '\t') break;
1247
1248 if (ch == cr) {
1249 parser->state = s_header_value_discard_ws_almost_done;
1250 break;
1251 }
1252
1253 if (ch == lf) {
1254 parser->state = s_header_value_discard_lws;
1255 break;
1256 }
1257
1258 /* fall through */
1259
1260 case s_header_value_start:
1261 {
1262 CROW_MARK(header_value);
1263
1264 parser->state = s_header_value;
1265 parser->index = 0;
1266
1267 c = CROW_LOWER(ch);
1268
1269 switch (parser->header_state) {
1270 case h_upgrade:
1271 // Crow does not support HTTP/2 at the moment.
1272 // According to the RFC https://datatracker.ietf.org/doc/html/rfc7540#section-3.2
1273 // "A server that does not support HTTP/2 can respond to the request as though the Upgrade header field were absent"
1274 // => `F_UPGRADE` is not set if the header starts by "h2".
1275 // This prevents the parser from skipping the request body.
1276 if (ch != 'h' || p+1 == (data + len) || *(p+1) != '2') {
1277 parser->flags |= F_UPGRADE;
1278 }
1279 parser->header_state = h_general;
1280 break;
1281
1282 case h_transfer_encoding:
1283 /* looking for 'Transfer-Encoding: chunked' */
1284 if ('c' == c) {
1285 parser->header_state = h_matching_transfer_encoding_chunked;
1286 } else {
1287 parser->header_state = h_matching_transfer_encoding_token;
1288 }
1289 break;
1290
1291 /* Multi-value `Transfer-Encoding` header */
1292 case h_matching_transfer_encoding_token_start:
1293 break;
1294
1295 case h_content_length:
1296 if (CROW_UNLIKELY(!CROW_IS_NUM(ch))) {
1297 CROW_SET_ERRNO(CHPE_INVALID_CONTENT_LENGTH);
1298 goto error;
1299 }
1300
1301 if (parser->flags & F_CONTENTLENGTH) {
1302 CROW_SET_ERRNO(CHPE_UNEXPECTED_CONTENT_LENGTH);
1303 goto error;
1304 }
1305 parser->flags |= F_CONTENTLENGTH;
1306 parser->content_length = ch - '0';
1307 parser->header_state = h_content_length_num;
1308 break;
1309
1310 /* when obsolete line folding is encountered for content length
1311 * continue to the s_header_value state */
1312 case h_content_length_ws:
1313 break;
1314
1315 case h_connection:
1316 /* looking for 'Connection: keep-alive' */
1317 if (c == 'k') {
1318 parser->header_state = h_matching_connection_keep_alive;
1319 /* looking for 'Connection: close' */
1320 } else if (c == 'c') {
1321 parser->header_state = h_matching_connection_close;
1322 } else if (c == ' ' || c == '\t') {
1323 /* Skip lws */
1324 } else {
1325 parser->header_state = h_general;
1326 }
1327 break;
1328
1329 default:
1330 parser->header_state = h_general;
1331 break;
1332 }
1333 break;
1334 }
1335
1336 case s_header_value:
1337 {
1338 const char* start = p;
1339 enum header_states h_state = static_cast<header_states>(parser->header_state);
1340 for (; p != data + len; p++) {
1341 ch = *p;
1342
1343 if (ch == cr) {
1344 parser->state = s_header_almost_done;
1345 parser->header_state = h_state;
1346 CROW_CALLBACK_DATA(header_value);
1347 break;
1348 }
1349
1350 if (ch == lf) {
1351 parser->state = s_header_almost_done;
1352 CROW_COUNT_HEADER_SIZE(p - start);
1353 parser->header_state = h_state;
1354 CROW_CALLBACK_DATA_NOADVANCE(header_value);
1355 CROW_REEXECUTE();
1356 }
1357
1358 if (!lenient && !CROW_IS_HEADER_CHAR(ch)) {
1359 CROW_SET_ERRNO(CHPE_INVALID_HEADER_TOKEN);
1360 goto error;
1361 }
1362
1363 c = CROW_LOWER(ch);
1364
1365 switch (h_state) {
1366 case h_general:
1367 {
1368 size_t left = data + len - p;
1369 const char* pe = p + CROW_MIN(left, max_header_size);
1370
1371 for (; p != pe; p++) {
1372 ch = *p;
1373 if (ch == cr || ch == lf) {
1374 --p;
1375 break;
1376 }
1377 if (!lenient && !CROW_IS_HEADER_CHAR(ch)) {
1378 CROW_SET_ERRNO(CHPE_INVALID_HEADER_TOKEN);
1379 goto error;
1380 }
1381 }
1382 if (p == data + len)
1383 --p;
1384 break;
1385 }
1386
1387 case h_connection:
1388 case h_transfer_encoding:
1389 assert(0 && "Shouldn't get here.");
1390 break;
1391
1392 case h_content_length:
1393 if (ch == ' ') break;
1394 h_state = h_content_length_num;
1395 /* fall through */
1396
1397 case h_content_length_num:
1398 {
1399 uint64_t t;
1400
1401 if (ch == ' ') {
1402 h_state = h_content_length_ws;
1403 break;
1404 }
1405
1406 if (CROW_UNLIKELY(!CROW_IS_NUM(ch))) {
1407 CROW_SET_ERRNO(CHPE_INVALID_CONTENT_LENGTH);
1408 parser->header_state = h_state;
1409 goto error;
1410 }
1411
1412 t = parser->content_length;
1413 t *= 10;
1414 t += ch - '0';
1415
1416 /* Overflow? Test against a conservative limit for simplicity. */
1417 if (CROW_UNLIKELY((CROW_ULLONG_MAX - 10) / 10 < parser->content_length)) {
1418 CROW_SET_ERRNO(CHPE_INVALID_CONTENT_LENGTH);
1419 parser->header_state = h_state;
1420 goto error;
1421 }
1422
1423 parser->content_length = t;
1424 break;
1425 }
1426
1427 case h_content_length_ws:
1428 if (ch == ' ') break;
1429 CROW_SET_ERRNO(CHPE_INVALID_CONTENT_LENGTH);
1430 parser->header_state = h_state;
1431 goto error;
1432
1433 /* Transfer-Encoding: chunked */
1434 case h_matching_transfer_encoding_token_start:
1435 /* looking for 'Transfer-Encoding: chunked' */
1436 if ('c' == c) {
1437 h_state = h_matching_transfer_encoding_chunked;
1438 } else if (CROW_TOKEN(c)) {
1439 /* TODO(indutny): similar code below does this, but why?
1440 * At the very least it seems to be inconsistent given that
1441 * h_matching_transfer_encoding_token does not check for
1442 * `STRICT_TOKEN`
1443 */
1444 h_state = h_matching_transfer_encoding_token;
1445 } else if (c == ' ' || c == '\t') {
1446 /* Skip lws */
1447 } else {
1448 h_state = h_general;
1449 }
1450 break;
1451
1452 case h_matching_transfer_encoding_chunked:
1453 parser->index++;
1454 if (parser->index > sizeof(CROW_CHUNKED)-1 || c != CROW_CHUNKED[parser->index]) {
1455 h_state = h_matching_transfer_encoding_token;
1456 } else if (parser->index == sizeof(CROW_CHUNKED)-2) {
1457 h_state = h_transfer_encoding_chunked;
1458 }
1459 break;
1460
1461 case h_matching_transfer_encoding_token:
1462 if (ch == ',') {
1463 h_state = h_matching_transfer_encoding_token_start;
1464 parser->index = 0;
1465 }
1466 break;
1467
1468 /* looking for 'Connection: keep-alive' */
1469 case h_matching_connection_keep_alive:
1470 parser->index++;
1471 if (parser->index > sizeof(CROW_KEEP_ALIVE)-1 || c != CROW_KEEP_ALIVE[parser->index]) {
1472 h_state = h_general;
1473 } else if (parser->index == sizeof(CROW_KEEP_ALIVE)-2) {
1474 h_state = h_connection_keep_alive;
1475 }
1476 break;
1477
1478 /* looking for 'Connection: close' */
1479 case h_matching_connection_close:
1480 parser->index++;
1481 if (parser->index > sizeof(CROW_CLOSE)-1 || c != CROW_CLOSE[parser->index]) {
1482 h_state = h_general;
1483 } else if (parser->index == sizeof(CROW_CLOSE)-2) {
1484 h_state = h_connection_close;
1485 }
1486 break;
1487
1488 // Edited from original (because of commits that werent included)
1489 case h_transfer_encoding_chunked:
1490 if (ch != ' ') h_state = h_matching_transfer_encoding_token;
1491 break;
1492 case h_connection_keep_alive:
1493 case h_connection_close:
1494 if (ch != ' ') h_state = h_general;
1495 break;
1496
1497 default:
1498 parser->state = s_header_value;
1499 h_state = h_general;
1500 break;
1501 }
1502 }
1503 parser->header_state = h_state;
1504
1505
1506 if (p == data + len)
1507 --p;
1508
1509 CROW_COUNT_HEADER_SIZE(p - start);
1510 break;
1511 }
1512
1513 case s_header_almost_done:
1514 {
1515 if (CROW_UNLIKELY(ch != lf)) {
1516 CROW_SET_ERRNO(CHPE_LF_EXPECTED);
1517 goto error;
1518 }
1519
1520 parser->state = s_header_value_lws;
1521 break;
1522 }
1523
1524 case s_header_value_lws:
1525 {
1526 if (ch == ' ' || ch == '\t') {
1527 if (parser->header_state == h_content_length_num) {
1528 /* treat obsolete line folding as space */
1529 parser->header_state = h_content_length_ws;
1530 }
1531 parser->state = s_header_value_start;
1532 CROW_REEXECUTE();
1533 }
1534
1535 /* finished the header */
1536 switch (parser->header_state) {
1537 case h_connection_keep_alive:
1538 parser->flags |= F_CONNECTION_KEEP_ALIVE;
1539 break;
1540 case h_connection_close:
1541 parser->flags |= F_CONNECTION_CLOSE;
1542 break;
1543 case h_transfer_encoding_chunked:
1544 parser->flags |= F_CHUNKED;
1545 break;
1546 default:
1547 break;
1548 }
1549
1550 parser->state = s_header_field_start;
1551 CROW_REEXECUTE();
1552 }
1553
1554 case s_header_value_discard_ws_almost_done:
1555 {
1556 CROW_STRICT_CHECK(ch != lf);
1557 parser->state = s_header_value_discard_lws;
1558 break;
1559 }
1560
1561 case s_header_value_discard_lws:
1562 {
1563 if (ch == ' ' || ch == '\t') {
1564 parser->state = s_header_value_discard_ws;
1565 break;
1566 } else {
1567 /* header value was empty */
1568 CROW_MARK(header_value);
1569 parser->state = s_header_field_start;
1570 CROW_CALLBACK_DATA_NOADVANCE(header_value);
1571 CROW_REEXECUTE();
1572 }
1573 }
1574
1575 case s_headers_almost_done:
1576 {
1577 CROW_STRICT_CHECK(ch != lf);
1578
1579 if (parser->flags & F_TRAILING) {
1580 /* End of a chunked request */
1581 CROW_CALLBACK_NOTIFY(message_complete);
1582 break;
1583 }
1584
1585 /* Cannot use transfer-encoding and a content-length header together
1586 per the HTTP specification. (RFC 7230 Section 3.3.3) */
1587 if ((parser->uses_transfer_encoding == 1) &&
1588 (parser->flags & F_CONTENTLENGTH)) {
1589 /* Allow it for lenient parsing as long as `Transfer-Encoding` is
1590 * not `chunked` or allow_length_with_encoding is set
1591 */
1592 if (parser->flags & F_CHUNKED) {
1593 if (!allow_chunked_length) {
1594 CROW_SET_ERRNO(CHPE_UNEXPECTED_CONTENT_LENGTH);
1595 goto error;
1596 }
1597 } else if (!lenient) {
1598 CROW_SET_ERRNO(CHPE_UNEXPECTED_CONTENT_LENGTH);
1599 goto error;
1600 }
1601 }
1602
1603 parser->state = s_headers_done;
1604
1605 /* Set this here so that on_headers_complete() callbacks can see it */
1606 parser->upgrade =
1607 (parser->flags & F_UPGRADE || parser->method == (unsigned)HTTPMethod::Connect);
1608
1609 /* Here we call the headers_complete callback. This is somewhat
1610 * different than other callbacks because if the user returns 1, we
1611 * will interpret that as saying that this message has no body. This
1612 * is needed for the annoying case of recieving a response to a HEAD
1613 * request.
1614 *
1615 * We'd like to use CROW_CALLBACK_NOTIFY_NOADVANCE() here but we cannot, so
1616 * we have to simulate it by handling a change in errno below.
1617 */
1618 if (settings->on_headers_complete) {
1619 switch (settings->on_headers_complete(parser)) {
1620 case 0:
1621 break;
1622
1623 case 2:
1624 parser->upgrade = 1;
1625 //break;
1626
1627 /* fall through */
1628 case 1:
1629 parser->flags |= F_SKIPBODY;
1630 break;
1631
1632 default:
1633 CROW_SET_ERRNO(CHPE_CB_headers_complete);
1634 parser->nread = nread;
1635 return p - data; /* Error */
1636 }
1637 }
1638
1639 if (CROW_HTTP_PARSER_ERRNO(parser) != CHPE_OK) {
1640 parser->nread = nread;
1641 return p - data;
1642 }
1643
1644 CROW_REEXECUTE();
1645 }
1646
1647 case s_headers_done:
1648 {
1649 CROW_STRICT_CHECK(ch != lf);
1650
1651 parser->nread = 0;
1652 nread = 0;
1653
1654 /* Exit, the rest of the connect is in a different protocol. */
1655 if (parser->upgrade) {
1656 CROW_CALLBACK_NOTIFY(message_complete);
1657 parser->nread = nread;
1658 return (p - data) + 1;
1659 }
1660
1661 if (parser->flags & F_SKIPBODY) {
1662 CROW_CALLBACK_NOTIFY(message_complete);
1663 } else if (parser->flags & F_CHUNKED) {
1664 /* chunked encoding - ignore Content-Length header,
1665 * prepare for a chunk */
1666 parser->state = s_chunk_size_start;
1667 }
1668 else if (parser->uses_transfer_encoding == 1)
1669 {
1670 if (!lenient)
1671 {
1672 /* RFC 7230 3.3.3 */
1673
1674 /* If a Transfer-Encoding header field
1675 * is present in a request and the chunked transfer coding is not
1676 * the final encoding, the message body length cannot be determined
1677 * reliably; the server MUST respond with the 400 (Bad Request)
1678 * status code and then close the connection.
1679 */
1680 CROW_SET_ERRNO(CHPE_INVALID_TRANSFER_ENCODING);
1681 parser->nread = nread;
1682 return (p - data); /* Error */
1683 }
1684 else
1685 {
1686 /* RFC 7230 3.3.3 */
1687
1688 /* If a Transfer-Encoding header field is present in a response and
1689 * the chunked transfer coding is not the final encoding, the
1690 * message body length is determined by reading the connection until
1691 * it is closed by the server.
1692 */
1693 parser->state = s_body_identity_eof;
1694 }
1695 }
1696 else
1697 {
1698 if (parser->content_length == 0)
1699 {
1700 /* Content-Length header given but zero: Content-Length: 0\r\n */
1701 CROW_CALLBACK_NOTIFY(message_complete);
1702 }
1703 else if (parser->content_length != CROW_ULLONG_MAX)
1704 {
1705 /* Content-Length header given and non-zero */
1706 parser->state = s_body_identity;
1707 }
1708 else
1709 {
1710 /* Assume content-length 0 - read the next */
1711 CROW_CALLBACK_NOTIFY(message_complete);
1712 }
1713 }
1714
1715 break;
1716 }
1717
1718 case s_body_identity:
1719 {
1720 uint64_t to_read = CROW_MIN(parser->content_length,
1721 (uint64_t) ((data + len) - p));
1722
1723 assert(parser->content_length != 0
1724 && parser->content_length != CROW_ULLONG_MAX);
1725
1726 /* The difference between advancing content_length and p is because
1727 * the latter will automaticaly advance on the next loop iteration.
1728 * Further, if content_length ends up at 0, we want to see the last
1729 * byte again for our message complete callback.
1730 */
1731 CROW_MARK(body);
1732 parser->content_length -= to_read;
1733 p += to_read - 1;
1734
1735 if (parser->content_length == 0) {
1736 parser->state = s_message_done;
1737
1738 /* Mimic CROW_CALLBACK_DATA_NOADVANCE() but with one extra byte.
1739 *
1740 * The alternative to doing this is to wait for the next byte to
1741 * trigger the data callback, just as in every other case. The
1742 * problem with this is that this makes it difficult for the test
1743 * harness to distinguish between complete-on-EOF and
1744 * complete-on-length. It's not clear that this distinction is
1745 * important for applications, but let's keep it for now.
1746 */
1747 CROW_CALLBACK_DATA_(body, p - body_mark + 1, p - data);
1748 CROW_REEXECUTE();
1749 }
1750
1751 break;
1752 }
1753
1754 /* read until EOF */
1755 case s_body_identity_eof:
1756 CROW_MARK(body);
1757 p = data + len - 1;
1758
1759 break;
1760
1761 case s_message_done:
1762 CROW_CALLBACK_NOTIFY(message_complete);
1763 break;
1764
1765 case s_chunk_size_start:
1766 {
1767 assert(nread == 1);
1768 assert(parser->flags & F_CHUNKED);
1769
1770 unhex_val = unhex[static_cast<unsigned char>(ch)];
1771 if (CROW_UNLIKELY(unhex_val == -1)) {
1772 CROW_SET_ERRNO(CHPE_INVALID_CHUNK_SIZE);
1773 goto error;
1774 }
1775
1776 parser->content_length = unhex_val;
1777 parser->state = s_chunk_size;
1778 break;
1779 }
1780
1781 case s_chunk_size:
1782 {
1783 uint64_t t;
1784
1785 assert(parser->flags & F_CHUNKED);
1786
1787 if (ch == cr) {
1788 parser->state = s_chunk_size_almost_done;
1789 break;
1790 }
1791
1792 unhex_val = unhex[static_cast<unsigned char>(ch)];
1793
1794 if (unhex_val == -1) {
1795 if (ch == ';' || ch == ' ') {
1796 parser->state = s_chunk_parameters;
1797 break;
1798 }
1799
1800 CROW_SET_ERRNO(CHPE_INVALID_CHUNK_SIZE);
1801 goto error;
1802 }
1803
1804 t = parser->content_length;
1805 t *= 16;
1806 t += unhex_val;
1807
1808 /* Overflow? Test against a conservative limit for simplicity. */
1809 if (CROW_UNLIKELY((CROW_ULLONG_MAX - 16) / 16 < parser->content_length)) {
1810 CROW_SET_ERRNO(CHPE_INVALID_CONTENT_LENGTH);
1811 goto error;
1812 }
1813
1814 parser->content_length = t;
1815 break;
1816 }
1817
1818 case s_chunk_parameters:
1819 {
1820 assert(parser->flags & F_CHUNKED);
1821 /* just ignore this shit. TODO check for overflow */
1822 if (ch == cr) {
1823 parser->state = s_chunk_size_almost_done;
1824 break;
1825 }
1826 /* A bare LF or other control character in a chunk extension would let
1827 * a peer that ends the chunk line at LF frame the body differently. */
1828 if (CROW_UNLIKELY(ch == lf || !CROW_IS_HEADER_CHAR(ch))) {
1829 CROW_SET_ERRNO(CHPE_INVALID_CHUNK_SIZE);
1830 goto error;
1831 }
1832 break;
1833 }
1834
1835 case s_chunk_size_almost_done:
1836 {
1837 assert(parser->flags & F_CHUNKED);
1838 CROW_STRICT_CHECK(ch != lf);
1839
1840 parser->nread = 0;
1841 nread = 0;
1842
1843 if (parser->content_length == 0) {
1844 parser->flags |= F_TRAILING;
1845 parser->state = s_header_field_start;
1846 } else {
1847 parser->state = s_chunk_data;
1848 }
1849 break;
1850 }
1851
1852 case s_chunk_data:
1853 {
1854 uint64_t to_read = CROW_MIN(parser->content_length,
1855 (uint64_t) ((data + len) - p));
1856
1857 assert(parser->flags & F_CHUNKED);
1858 assert(parser->content_length != 0
1859 && parser->content_length != CROW_ULLONG_MAX);
1860
1861 /* See the explanation in s_body_identity for why the content
1862 * length and data pointers are managed this way.
1863 */
1864 CROW_MARK(body);
1865 parser->content_length -= to_read;
1866 p += to_read - 1;
1867
1868 if (parser->content_length == 0) {
1869 parser->state = s_chunk_data_almost_done;
1870 }
1871
1872 break;
1873 }
1874
1875 case s_chunk_data_almost_done:
1876 assert(parser->flags & F_CHUNKED);
1877 assert(parser->content_length == 0);
1878 CROW_STRICT_CHECK(ch != cr);
1879 parser->state = s_chunk_data_done;
1880 CROW_CALLBACK_DATA(body);
1881 break;
1882
1883 case s_chunk_data_done:
1884 assert(parser->flags & F_CHUNKED);
1885 CROW_STRICT_CHECK(ch != lf);
1886 parser->nread = 0;
1887 nread = 0;
1888 parser->state = s_chunk_size_start;
1889 break;
1890
1891 default:
1892 assert(0 && "unhandled state");
1893 CROW_SET_ERRNO(CHPE_INVALID_INTERNAL_STATE);
1894 goto error;
1895 }
1896 }
1897
1898 /* Run callbacks for any marks that we have leftover after we ran out of
1899 * bytes. There should be at most one of these set, so it's OK to invoke
1900 * them in series (unset marks will not result in callbacks).
1901 *
1902 * We use the NOADVANCE() variety of callbacks here because 'p' has already
1903 * overflowed 'data' and this allows us to correct for the off-by-one that
1904 * we'd otherwise have (since CROW_CALLBACK_DATA() is meant to be run with a 'p'
1905 * value that's in-bounds).
1906 */
1907
1908 assert(((header_field_mark ? 1 : 0) +
1909 (header_value_mark ? 1 : 0) +
1910 (url_mark ? 1 : 0) +
1911 (body_mark ? 1 : 0)) <= 1);
1912
1913 CROW_CALLBACK_DATA_NOADVANCE(header_field);
1914 CROW_CALLBACK_DATA_NOADVANCE(header_value);
1915 CROW_CALLBACK_DATA_NOADVANCE(url);
1916 CROW_CALLBACK_DATA_NOADVANCE(body);
1917
1918 parser->nread = nread;
1919 return len;
1920
1921error:
1922 if (CROW_HTTP_PARSER_ERRNO(parser) == CHPE_OK) {
1923 CROW_SET_ERRNO(CHPE_UNKNOWN);
1924 }
1925
1926 parser->nread = nread;
1927 return (p - data);
1928}
1929
1930inline void
1931 http_parser_init(http_parser* parser)
1932{
1933 void *data = parser->data; /* preserve application data */
1934 memset(parser, 0, sizeof(*parser));
1935 parser->data = data;
1936 parser->state = s_start_req;
1937 parser->http_errno = CHPE_OK;
1938}
1939
1940/* Return a string name of the given error */
1941inline const char *
1942http_errno_name(enum http_errno err) {
1943/* Map errno values to strings for human-readable output */
1944#define CROW_HTTP_STRERROR_GEN(n, s) { "CHPE_" #n, s },
1945static struct {
1946 const char *name;
1947 const char *description;
1948} http_strerror_tab[] = {
1949 CROW_HTTP_ERRNO_MAP(CROW_HTTP_STRERROR_GEN)
1950};
1951#undef CROW_HTTP_STRERROR_GEN
1952 assert(((size_t) err) < CROW_ARRAY_SIZE(http_strerror_tab));
1953 return http_strerror_tab[err].name;
1954}
1955
1956/* Return a string description of the given error */
1957inline const char *
1958http_errno_description(enum http_errno err) {
1959/* Map errno values to strings for human-readable output */
1960#define CROW_HTTP_STRERROR_GEN(n, s) { "CHPE_" #n, s },
1961static struct {
1962 const char *name;
1963 const char *description;
1964} http_strerror_tab[] = {
1965 CROW_HTTP_ERRNO_MAP(CROW_HTTP_STRERROR_GEN)
1966};
1967#undef CROW_HTTP_STRERROR_GEN
1968 assert(((size_t) err) < CROW_ARRAY_SIZE(http_strerror_tab));
1969 return http_strerror_tab[err].description;
1970}
1971
1972/* Checks if this is the final chunk of the body. */
1973inline int
1974http_body_is_final(const struct http_parser *parser) {
1975 return parser->state == s_message_done;
1976}
1977
1978/* Change the maximum header size provided at compile time. */
1979inline void
1980http_parser_set_max_header_size(uint32_t size) {
1981 max_header_size = size;
1982}
1983
1984#undef CROW_HTTP_ERRNO_MAP
1985#undef CROW_SET_ERRNO
1986#undef CROW_CALLBACK_NOTIFY_
1987#undef CROW_CALLBACK_NOTIFY
1988#undef CROW_CALLBACK_NOTIFY_NOADVANCE
1989#undef CROW_CALLBACK_DATA_
1990#undef CROW_CALLBACK_DATA
1991#undef CROW_CALLBACK_DATA_NOADVANCE
1992#undef CROW_MARK
1993#undef CROW_PROXY_CONNECTION
1994#undef CROW_CONNECTION
1995#undef CROW_CONTENT_LENGTH
1996#undef CROW_TRANSFER_ENCODING
1997#undef CROW_UPGRADE
1998#undef CROW_CHUNKED
1999#undef CROW_KEEP_ALIVE
2000#undef CROW_CLOSE
2001#undef CROW_PARSING_HEADER
2002#undef CROW_LOWER
2003#undef CROW_IS_ALPHA
2004#undef CROW_IS_NUM
2005#undef CROW_IS_ALPHANUM
2006//#undef CROW_IS_HEX
2007#undef CROW_IS_MARK
2008#undef CROW_IS_USERINFO_CHAR
2009#undef CROW_TOKEN
2010#undef CROW_IS_URL_CHAR
2011//#undef CROW_IS_HOST_CHAR
2012#undef CROW_STRICT_CHECK
2013
2014}
2015
2016// clang-format on
The main namespace of the library. In this namespace is defined the most important classes and functi...
Definition http_parser_merged.h:180
Definition http_parser_merged.h:148
unsigned char http_major
Definition http_parser_merged.h:162
unsigned int flags
Definition http_parser_merged.h:150
void * data
Definition http_parser_merged.h:175