llhttp 0.0.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,587 @@
1
+ // This software is licensed under the MIT License.
2
+
3
+ // Copyright Fedor Indutny, 2018.
4
+
5
+ // Permission is hereby granted, free of charge, to any person obtaining a
6
+ // copy of this software and associated documentation files (the
7
+ // "Software"), to deal in the Software without restriction, including
8
+ // without limitation the rights to use, copy, modify, merge, publish,
9
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
10
+ // persons to whom the Software is furnished to do so, subject to the
11
+ // following conditions:
12
+
13
+ // The above copyright notice and this permission notice shall be included
14
+ // in all copies or substantial portions of the Software.
15
+
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ #ifndef INCLUDE_LLHTTP_H_
25
+ #define INCLUDE_LLHTTP_H_
26
+
27
+ #define LLHTTP_VERSION_MAJOR 6
28
+ #define LLHTTP_VERSION_MINOR 0
29
+ #define LLHTTP_VERSION_PATCH 1
30
+
31
+ #ifndef LLHTTP_STRICT_MODE
32
+ # define LLHTTP_STRICT_MODE 0
33
+ #endif
34
+
35
+ #ifndef INCLUDE_LLHTTP_ITSELF_H_
36
+ #define INCLUDE_LLHTTP_ITSELF_H_
37
+ #ifdef __cplusplus
38
+ extern "C" {
39
+ #endif
40
+
41
+ #include <stdint.h>
42
+
43
+ typedef struct llhttp__internal_s llhttp__internal_t;
44
+ struct llhttp__internal_s {
45
+ int32_t _index;
46
+ void* _span_pos0;
47
+ void* _span_cb0;
48
+ int32_t error;
49
+ const char* reason;
50
+ const char* error_pos;
51
+ void* data;
52
+ void* _current;
53
+ uint64_t content_length;
54
+ uint8_t type;
55
+ uint8_t method;
56
+ uint8_t http_major;
57
+ uint8_t http_minor;
58
+ uint8_t header_state;
59
+ uint8_t lenient_flags;
60
+ uint8_t upgrade;
61
+ uint8_t finish;
62
+ uint16_t flags;
63
+ uint16_t status_code;
64
+ void* settings;
65
+ };
66
+
67
+ int llhttp__internal_init(llhttp__internal_t* s);
68
+ int llhttp__internal_execute(llhttp__internal_t* s, const char* p, const char* endp);
69
+
70
+ #ifdef __cplusplus
71
+ } /* extern "C" */
72
+ #endif
73
+ #endif /* INCLUDE_LLHTTP_ITSELF_H_ */
74
+
75
+ #ifndef LLLLHTTP_C_HEADERS_
76
+ #define LLLLHTTP_C_HEADERS_
77
+ #ifdef __cplusplus
78
+ extern "C" {
79
+ #endif
80
+
81
+ enum llhttp_errno {
82
+ HPE_OK = 0,
83
+ HPE_INTERNAL = 1,
84
+ HPE_STRICT = 2,
85
+ HPE_LF_EXPECTED = 3,
86
+ HPE_UNEXPECTED_CONTENT_LENGTH = 4,
87
+ HPE_CLOSED_CONNECTION = 5,
88
+ HPE_INVALID_METHOD = 6,
89
+ HPE_INVALID_URL = 7,
90
+ HPE_INVALID_CONSTANT = 8,
91
+ HPE_INVALID_VERSION = 9,
92
+ HPE_INVALID_HEADER_TOKEN = 10,
93
+ HPE_INVALID_CONTENT_LENGTH = 11,
94
+ HPE_INVALID_CHUNK_SIZE = 12,
95
+ HPE_INVALID_STATUS = 13,
96
+ HPE_INVALID_EOF_STATE = 14,
97
+ HPE_INVALID_TRANSFER_ENCODING = 15,
98
+ HPE_CB_MESSAGE_BEGIN = 16,
99
+ HPE_CB_HEADERS_COMPLETE = 17,
100
+ HPE_CB_MESSAGE_COMPLETE = 18,
101
+ HPE_CB_CHUNK_HEADER = 19,
102
+ HPE_CB_CHUNK_COMPLETE = 20,
103
+ HPE_PAUSED = 21,
104
+ HPE_PAUSED_UPGRADE = 22,
105
+ HPE_PAUSED_H2_UPGRADE = 23,
106
+ HPE_USER = 24
107
+ };
108
+ typedef enum llhttp_errno llhttp_errno_t;
109
+
110
+ enum llhttp_flags {
111
+ F_CONNECTION_KEEP_ALIVE = 0x1,
112
+ F_CONNECTION_CLOSE = 0x2,
113
+ F_CONNECTION_UPGRADE = 0x4,
114
+ F_CHUNKED = 0x8,
115
+ F_UPGRADE = 0x10,
116
+ F_CONTENT_LENGTH = 0x20,
117
+ F_SKIPBODY = 0x40,
118
+ F_TRAILING = 0x80,
119
+ F_TRANSFER_ENCODING = 0x200
120
+ };
121
+ typedef enum llhttp_flags llhttp_flags_t;
122
+
123
+ enum llhttp_lenient_flags {
124
+ LENIENT_HEADERS = 0x1,
125
+ LENIENT_CHUNKED_LENGTH = 0x2,
126
+ LENIENT_KEEP_ALIVE = 0x4
127
+ };
128
+ typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
129
+
130
+ enum llhttp_type {
131
+ HTTP_BOTH = 0,
132
+ HTTP_REQUEST = 1,
133
+ HTTP_RESPONSE = 2
134
+ };
135
+ typedef enum llhttp_type llhttp_type_t;
136
+
137
+ enum llhttp_finish {
138
+ HTTP_FINISH_SAFE = 0,
139
+ HTTP_FINISH_SAFE_WITH_CB = 1,
140
+ HTTP_FINISH_UNSAFE = 2
141
+ };
142
+ typedef enum llhttp_finish llhttp_finish_t;
143
+
144
+ enum llhttp_method {
145
+ HTTP_DELETE = 0,
146
+ HTTP_GET = 1,
147
+ HTTP_HEAD = 2,
148
+ HTTP_POST = 3,
149
+ HTTP_PUT = 4,
150
+ HTTP_CONNECT = 5,
151
+ HTTP_OPTIONS = 6,
152
+ HTTP_TRACE = 7,
153
+ HTTP_COPY = 8,
154
+ HTTP_LOCK = 9,
155
+ HTTP_MKCOL = 10,
156
+ HTTP_MOVE = 11,
157
+ HTTP_PROPFIND = 12,
158
+ HTTP_PROPPATCH = 13,
159
+ HTTP_SEARCH = 14,
160
+ HTTP_UNLOCK = 15,
161
+ HTTP_BIND = 16,
162
+ HTTP_REBIND = 17,
163
+ HTTP_UNBIND = 18,
164
+ HTTP_ACL = 19,
165
+ HTTP_REPORT = 20,
166
+ HTTP_MKACTIVITY = 21,
167
+ HTTP_CHECKOUT = 22,
168
+ HTTP_MERGE = 23,
169
+ HTTP_MSEARCH = 24,
170
+ HTTP_NOTIFY = 25,
171
+ HTTP_SUBSCRIBE = 26,
172
+ HTTP_UNSUBSCRIBE = 27,
173
+ HTTP_PATCH = 28,
174
+ HTTP_PURGE = 29,
175
+ HTTP_MKCALENDAR = 30,
176
+ HTTP_LINK = 31,
177
+ HTTP_UNLINK = 32,
178
+ HTTP_SOURCE = 33,
179
+ HTTP_PRI = 34,
180
+ HTTP_DESCRIBE = 35,
181
+ HTTP_ANNOUNCE = 36,
182
+ HTTP_SETUP = 37,
183
+ HTTP_PLAY = 38,
184
+ HTTP_PAUSE = 39,
185
+ HTTP_TEARDOWN = 40,
186
+ HTTP_GET_PARAMETER = 41,
187
+ HTTP_SET_PARAMETER = 42,
188
+ HTTP_REDIRECT = 43,
189
+ HTTP_RECORD = 44,
190
+ HTTP_FLUSH = 45
191
+ };
192
+ typedef enum llhttp_method llhttp_method_t;
193
+
194
+ #define HTTP_ERRNO_MAP(XX) \
195
+ XX(0, OK, OK) \
196
+ XX(1, INTERNAL, INTERNAL) \
197
+ XX(2, STRICT, STRICT) \
198
+ XX(3, LF_EXPECTED, LF_EXPECTED) \
199
+ XX(4, UNEXPECTED_CONTENT_LENGTH, UNEXPECTED_CONTENT_LENGTH) \
200
+ XX(5, CLOSED_CONNECTION, CLOSED_CONNECTION) \
201
+ XX(6, INVALID_METHOD, INVALID_METHOD) \
202
+ XX(7, INVALID_URL, INVALID_URL) \
203
+ XX(8, INVALID_CONSTANT, INVALID_CONSTANT) \
204
+ XX(9, INVALID_VERSION, INVALID_VERSION) \
205
+ XX(10, INVALID_HEADER_TOKEN, INVALID_HEADER_TOKEN) \
206
+ XX(11, INVALID_CONTENT_LENGTH, INVALID_CONTENT_LENGTH) \
207
+ XX(12, INVALID_CHUNK_SIZE, INVALID_CHUNK_SIZE) \
208
+ XX(13, INVALID_STATUS, INVALID_STATUS) \
209
+ XX(14, INVALID_EOF_STATE, INVALID_EOF_STATE) \
210
+ XX(15, INVALID_TRANSFER_ENCODING, INVALID_TRANSFER_ENCODING) \
211
+ XX(16, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \
212
+ XX(17, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \
213
+ XX(18, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \
214
+ XX(19, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \
215
+ XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
216
+ XX(21, PAUSED, PAUSED) \
217
+ XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
218
+ XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \
219
+ XX(24, USER, USER) \
220
+
221
+
222
+ #define HTTP_METHOD_MAP(XX) \
223
+ XX(0, DELETE, DELETE) \
224
+ XX(1, GET, GET) \
225
+ XX(2, HEAD, HEAD) \
226
+ XX(3, POST, POST) \
227
+ XX(4, PUT, PUT) \
228
+ XX(5, CONNECT, CONNECT) \
229
+ XX(6, OPTIONS, OPTIONS) \
230
+ XX(7, TRACE, TRACE) \
231
+ XX(8, COPY, COPY) \
232
+ XX(9, LOCK, LOCK) \
233
+ XX(10, MKCOL, MKCOL) \
234
+ XX(11, MOVE, MOVE) \
235
+ XX(12, PROPFIND, PROPFIND) \
236
+ XX(13, PROPPATCH, PROPPATCH) \
237
+ XX(14, SEARCH, SEARCH) \
238
+ XX(15, UNLOCK, UNLOCK) \
239
+ XX(16, BIND, BIND) \
240
+ XX(17, REBIND, REBIND) \
241
+ XX(18, UNBIND, UNBIND) \
242
+ XX(19, ACL, ACL) \
243
+ XX(20, REPORT, REPORT) \
244
+ XX(21, MKACTIVITY, MKACTIVITY) \
245
+ XX(22, CHECKOUT, CHECKOUT) \
246
+ XX(23, MERGE, MERGE) \
247
+ XX(24, MSEARCH, M-SEARCH) \
248
+ XX(25, NOTIFY, NOTIFY) \
249
+ XX(26, SUBSCRIBE, SUBSCRIBE) \
250
+ XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
251
+ XX(28, PATCH, PATCH) \
252
+ XX(29, PURGE, PURGE) \
253
+ XX(30, MKCALENDAR, MKCALENDAR) \
254
+ XX(31, LINK, LINK) \
255
+ XX(32, UNLINK, UNLINK) \
256
+ XX(33, SOURCE, SOURCE) \
257
+
258
+
259
+ #define RTSP_METHOD_MAP(XX) \
260
+ XX(1, GET, GET) \
261
+ XX(3, POST, POST) \
262
+ XX(6, OPTIONS, OPTIONS) \
263
+ XX(35, DESCRIBE, DESCRIBE) \
264
+ XX(36, ANNOUNCE, ANNOUNCE) \
265
+ XX(37, SETUP, SETUP) \
266
+ XX(38, PLAY, PLAY) \
267
+ XX(39, PAUSE, PAUSE) \
268
+ XX(40, TEARDOWN, TEARDOWN) \
269
+ XX(41, GET_PARAMETER, GET_PARAMETER) \
270
+ XX(42, SET_PARAMETER, SET_PARAMETER) \
271
+ XX(43, REDIRECT, REDIRECT) \
272
+ XX(44, RECORD, RECORD) \
273
+ XX(45, FLUSH, FLUSH) \
274
+
275
+
276
+ #define HTTP_ALL_METHOD_MAP(XX) \
277
+ XX(0, DELETE, DELETE) \
278
+ XX(1, GET, GET) \
279
+ XX(2, HEAD, HEAD) \
280
+ XX(3, POST, POST) \
281
+ XX(4, PUT, PUT) \
282
+ XX(5, CONNECT, CONNECT) \
283
+ XX(6, OPTIONS, OPTIONS) \
284
+ XX(7, TRACE, TRACE) \
285
+ XX(8, COPY, COPY) \
286
+ XX(9, LOCK, LOCK) \
287
+ XX(10, MKCOL, MKCOL) \
288
+ XX(11, MOVE, MOVE) \
289
+ XX(12, PROPFIND, PROPFIND) \
290
+ XX(13, PROPPATCH, PROPPATCH) \
291
+ XX(14, SEARCH, SEARCH) \
292
+ XX(15, UNLOCK, UNLOCK) \
293
+ XX(16, BIND, BIND) \
294
+ XX(17, REBIND, REBIND) \
295
+ XX(18, UNBIND, UNBIND) \
296
+ XX(19, ACL, ACL) \
297
+ XX(20, REPORT, REPORT) \
298
+ XX(21, MKACTIVITY, MKACTIVITY) \
299
+ XX(22, CHECKOUT, CHECKOUT) \
300
+ XX(23, MERGE, MERGE) \
301
+ XX(24, MSEARCH, M-SEARCH) \
302
+ XX(25, NOTIFY, NOTIFY) \
303
+ XX(26, SUBSCRIBE, SUBSCRIBE) \
304
+ XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
305
+ XX(28, PATCH, PATCH) \
306
+ XX(29, PURGE, PURGE) \
307
+ XX(30, MKCALENDAR, MKCALENDAR) \
308
+ XX(31, LINK, LINK) \
309
+ XX(32, UNLINK, UNLINK) \
310
+ XX(33, SOURCE, SOURCE) \
311
+ XX(34, PRI, PRI) \
312
+ XX(35, DESCRIBE, DESCRIBE) \
313
+ XX(36, ANNOUNCE, ANNOUNCE) \
314
+ XX(37, SETUP, SETUP) \
315
+ XX(38, PLAY, PLAY) \
316
+ XX(39, PAUSE, PAUSE) \
317
+ XX(40, TEARDOWN, TEARDOWN) \
318
+ XX(41, GET_PARAMETER, GET_PARAMETER) \
319
+ XX(42, SET_PARAMETER, SET_PARAMETER) \
320
+ XX(43, REDIRECT, REDIRECT) \
321
+ XX(44, RECORD, RECORD) \
322
+ XX(45, FLUSH, FLUSH) \
323
+
324
+
325
+ #ifdef __cplusplus
326
+ } /* extern "C" */
327
+ #endif
328
+ #endif /* LLLLHTTP_C_HEADERS_ */
329
+
330
+ #ifndef INCLUDE_LLHTTP_API_H_
331
+ #define INCLUDE_LLHTTP_API_H_
332
+ #ifdef __cplusplus
333
+ extern "C" {
334
+ #endif
335
+ #include <stddef.h>
336
+
337
+ #if defined(__wasm__)
338
+ #define LLHTTP_EXPORT __attribute__((visibility("default")))
339
+ #else
340
+ #define LLHTTP_EXPORT
341
+ #endif
342
+
343
+ typedef llhttp__internal_t llhttp_t;
344
+ typedef struct llhttp_settings_s llhttp_settings_t;
345
+
346
+ typedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length);
347
+ typedef int (*llhttp_cb)(llhttp_t*);
348
+
349
+ struct llhttp_settings_s {
350
+ /* Possible return values 0, -1, `HPE_PAUSED` */
351
+ llhttp_cb on_message_begin;
352
+
353
+ /* Possible return values 0, -1, HPE_USER */
354
+ llhttp_data_cb on_url;
355
+ llhttp_data_cb on_status;
356
+ llhttp_data_cb on_header_field;
357
+ llhttp_data_cb on_header_value;
358
+
359
+ /* Possible return values:
360
+ * 0 - Proceed normally
361
+ * 1 - Assume that request/response has no body, and proceed to parsing the
362
+ * next message
363
+ * 2 - Assume absence of body (as above) and make `llhttp_execute()` return
364
+ * `HPE_PAUSED_UPGRADE`
365
+ * -1 - Error
366
+ * `HPE_PAUSED`
367
+ */
368
+ llhttp_cb on_headers_complete;
369
+
370
+ /* Possible return values 0, -1, HPE_USER */
371
+ llhttp_data_cb on_body;
372
+
373
+ /* Possible return values 0, -1, `HPE_PAUSED` */
374
+ llhttp_cb on_message_complete;
375
+
376
+ /* When on_chunk_header is called, the current chunk length is stored
377
+ * in parser->content_length.
378
+ * Possible return values 0, -1, `HPE_PAUSED`
379
+ */
380
+ llhttp_cb on_chunk_header;
381
+ llhttp_cb on_chunk_complete;
382
+
383
+ /* Information-only callbacks, return value is ignored */
384
+ llhttp_cb on_url_complete;
385
+ llhttp_cb on_status_complete;
386
+ llhttp_cb on_header_field_complete;
387
+ llhttp_cb on_header_value_complete;
388
+ };
389
+
390
+ /* Initialize the parser with specific type and user settings.
391
+ *
392
+ * NOTE: lifetime of `settings` has to be at least the same as the lifetime of
393
+ * the `parser` here. In practice, `settings` has to be either a static
394
+ * variable or be allocated with `malloc`, `new`, etc.
395
+ */
396
+ LLHTTP_EXPORT
397
+ void llhttp_init(llhttp_t* parser, llhttp_type_t type,
398
+ const llhttp_settings_t* settings);
399
+
400
+ #if defined(__wasm__)
401
+
402
+ LLHTTP_EXPORT
403
+ llhttp_t* llhttp_alloc(llhttp_type_t type);
404
+
405
+ LLHTTP_EXPORT
406
+ void llhttp_free(llhttp_t* parser);
407
+
408
+ LLHTTP_EXPORT
409
+ uint8_t llhttp_get_type(llhttp_t* parser);
410
+
411
+ LLHTTP_EXPORT
412
+ uint8_t llhttp_get_http_major(llhttp_t* parser);
413
+
414
+ LLHTTP_EXPORT
415
+ uint8_t llhttp_get_http_minor(llhttp_t* parser);
416
+
417
+ LLHTTP_EXPORT
418
+ uint8_t llhttp_get_method(llhttp_t* parser);
419
+
420
+ LLHTTP_EXPORT
421
+ int llhttp_get_status_code(llhttp_t* parser);
422
+
423
+ LLHTTP_EXPORT
424
+ uint8_t llhttp_get_upgrade(llhttp_t* parser);
425
+
426
+ #endif // defined(__wasm__)
427
+
428
+ /* Reset an already initialized parser back to the start state, preserving the
429
+ * existing parser type, callback settings, user data, and lenient flags.
430
+ */
431
+ LLHTTP_EXPORT
432
+ void llhttp_reset(llhttp_t* parser);
433
+
434
+ /* Initialize the settings object */
435
+ LLHTTP_EXPORT
436
+ void llhttp_settings_init(llhttp_settings_t* settings);
437
+
438
+ /* Parse full or partial request/response, invoking user callbacks along the
439
+ * way.
440
+ *
441
+ * If any of `llhttp_data_cb` returns errno not equal to `HPE_OK` - the parsing
442
+ * interrupts, and such errno is returned from `llhttp_execute()`. If
443
+ * `HPE_PAUSED` was used as a errno, the execution can be resumed with
444
+ * `llhttp_resume()` call.
445
+ *
446
+ * In a special case of CONNECT/Upgrade request/response `HPE_PAUSED_UPGRADE`
447
+ * is returned after fully parsing the request/response. If the user wishes to
448
+ * continue parsing, they need to invoke `llhttp_resume_after_upgrade()`.
449
+ *
450
+ * NOTE: if this function ever returns a non-pause type error, it will continue
451
+ * to return the same error upon each successive call up until `llhttp_init()`
452
+ * is called.
453
+ */
454
+ LLHTTP_EXPORT
455
+ llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
456
+
457
+ /* This method should be called when the other side has no further bytes to
458
+ * send (e.g. shutdown of readable side of the TCP connection.)
459
+ *
460
+ * Requests without `Content-Length` and other messages might require treating
461
+ * all incoming bytes as the part of the body, up to the last byte of the
462
+ * connection. This method will invoke `on_message_complete()` callback if the
463
+ * request was terminated safely. Otherwise a error code would be returned.
464
+ */
465
+ LLHTTP_EXPORT
466
+ llhttp_errno_t llhttp_finish(llhttp_t* parser);
467
+
468
+ /* Returns `1` if the incoming message is parsed until the last byte, and has
469
+ * to be completed by calling `llhttp_finish()` on EOF
470
+ */
471
+ LLHTTP_EXPORT
472
+ int llhttp_message_needs_eof(const llhttp_t* parser);
473
+
474
+ /* Returns `1` if there might be any other messages following the last that was
475
+ * successfully parsed.
476
+ */
477
+ LLHTTP_EXPORT
478
+ int llhttp_should_keep_alive(const llhttp_t* parser);
479
+
480
+ /* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
481
+ * appropriate error reason.
482
+ *
483
+ * Important: do not call this from user callbacks! User callbacks must return
484
+ * `HPE_PAUSED` if pausing is required.
485
+ */
486
+ LLHTTP_EXPORT
487
+ void llhttp_pause(llhttp_t* parser);
488
+
489
+ /* Might be called to resume the execution after the pause in user's callback.
490
+ * See `llhttp_execute()` above for details.
491
+ *
492
+ * Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
493
+ */
494
+ LLHTTP_EXPORT
495
+ void llhttp_resume(llhttp_t* parser);
496
+
497
+ /* Might be called to resume the execution after the pause in user's callback.
498
+ * See `llhttp_execute()` above for details.
499
+ *
500
+ * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
501
+ */
502
+ LLHTTP_EXPORT
503
+ void llhttp_resume_after_upgrade(llhttp_t* parser);
504
+
505
+ /* Returns the latest return error */
506
+ LLHTTP_EXPORT
507
+ llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
508
+
509
+ /* Returns the verbal explanation of the latest returned error.
510
+ *
511
+ * Note: User callback should set error reason when returning the error. See
512
+ * `llhttp_set_error_reason()` for details.
513
+ */
514
+ LLHTTP_EXPORT
515
+ const char* llhttp_get_error_reason(const llhttp_t* parser);
516
+
517
+ /* Assign verbal description to the returned error. Must be called in user
518
+ * callbacks right before returning the errno.
519
+ *
520
+ * Note: `HPE_USER` error code might be useful in user callbacks.
521
+ */
522
+ LLHTTP_EXPORT
523
+ void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
524
+
525
+ /* Returns the pointer to the last parsed byte before the returned error. The
526
+ * pointer is relative to the `data` argument of `llhttp_execute()`.
527
+ *
528
+ * Note: this method might be useful for counting the number of parsed bytes.
529
+ */
530
+ LLHTTP_EXPORT
531
+ const char* llhttp_get_error_pos(const llhttp_t* parser);
532
+
533
+ /* Returns textual name of error code */
534
+ LLHTTP_EXPORT
535
+ const char* llhttp_errno_name(llhttp_errno_t err);
536
+
537
+ /* Returns textual name of HTTP method */
538
+ LLHTTP_EXPORT
539
+ const char* llhttp_method_name(llhttp_method_t method);
540
+
541
+
542
+ /* Enables/disables lenient header value parsing (disabled by default).
543
+ *
544
+ * Lenient parsing disables header value token checks, extending llhttp's
545
+ * protocol support to highly non-compliant clients/server. No
546
+ * `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
547
+ * lenient parsing is "on".
548
+ *
549
+ * **(USE AT YOUR OWN RISK)**
550
+ */
551
+ LLHTTP_EXPORT
552
+ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
553
+
554
+
555
+ /* Enables/disables lenient handling of conflicting `Transfer-Encoding` and
556
+ * `Content-Length` headers (disabled by default).
557
+ *
558
+ * Normally `llhttp` would error when `Transfer-Encoding` is present in
559
+ * conjunction with `Content-Length`. This error is important to prevent HTTP
560
+ * request smuggling, but may be less desirable for small number of cases
561
+ * involving legacy servers.
562
+ *
563
+ * **(USE AT YOUR OWN RISK)**
564
+ */
565
+ LLHTTP_EXPORT
566
+ void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
567
+
568
+
569
+ /* Enables/disables lenient handling of `Connection: close` and HTTP/1.0
570
+ * requests responses.
571
+ *
572
+ * Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
573
+ * the HTTP request/response after the request/response with `Connection: close`
574
+ * and `Content-Length`. This is important to prevent cache poisoning attacks,
575
+ * but might interact badly with outdated and insecure clients. With this flag
576
+ * the extra request/response will be parsed normally.
577
+ *
578
+ * **(USE AT YOUR OWN RISK)**
579
+ */
580
+ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled);
581
+
582
+ #ifdef __cplusplus
583
+ } /* extern "C" */
584
+ #endif
585
+ #endif /* INCLUDE_LLHTTP_API_H_ */
586
+
587
+ #endif /* INCLUDE_LLHTTP_H_ */