Skip to content

Commit 6a1986d

Browse files
committed
deps: update llhttp to 5.1.0
PR-URL: #38146 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Daniele Belardi <[email protected]>
1 parent 5ba5cc8 commit 6a1986d

13 files changed

+3241
-1375
lines changed

Diff for: deps/llhttp/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# llhttp
2+
[![CI](https://github.com/nodejs/llhttp/workflows/CI/badge.svg)](https://github.com/nodejs/llhttp/actions?query=workflow%3ACI)
23

34
Port of [http_parser][0] to [llparse][1].
45

@@ -31,7 +32,7 @@ So far llhttp outperforms http_parser:
3132

3233
| | input size | bandwidth | reqs/sec | time |
3334
|:----------------|-----------:|-------------:|-----------:|--------:|
34-
| **llhttp** | 8192.00 mb | 1777.24 mb/s | 3583799.39 ops/sec | 4.61 s |
35+
| **llhttp** | 8192.00 mb | 1777.24 mb/s | 3583799.39 req/sec | 4.61 s |
3536
| **http_parser** | 8192.00 mb | 694.66 mb/s | 1406180.33 req/sec | 11.79 s |
3637

3738
llhttp is faster by approximately **156%**.
@@ -92,6 +93,11 @@ if (err == HPE_OK) {
9293
9394
---
9495
96+
### Bindings to other languages
97+
98+
* Python: [pallas/pyllhttp][8]
99+
* Ruby: [metabahn/llhttp][9]
100+
95101
#### LICENSE
96102
97103
This software is licensed under the MIT License.
@@ -125,3 +131,5 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
125131
[5]: https://llvm.org/docs/LangRef.html#call-instruction
126132
[6]: https://clang.llvm.org/
127133
[7]: https://github.com/nodejs/node
134+
[8]: https://github.com/pallas/pyllhttp
135+
[9]: https://github.com/metabahn/llhttp

Diff for: deps/llhttp/include/llhttp.h

+135-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef INCLUDE_LLHTTP_H_
22
#define INCLUDE_LLHTTP_H_
33

4-
#define LLHTTP_VERSION_MAJOR 2
4+
#define LLHTTP_VERSION_MAJOR 5
55
#define LLHTTP_VERSION_MINOR 1
6-
#define LLHTTP_VERSION_PATCH 3
6+
#define LLHTTP_VERSION_PATCH 0
77

88
#ifndef LLHTTP_STRICT_MODE
99
# define LLHTTP_STRICT_MODE 0
@@ -33,10 +33,11 @@ struct llhttp__internal_s {
3333
uint8_t http_major;
3434
uint8_t http_minor;
3535
uint8_t header_state;
36-
uint16_t flags;
36+
uint8_t lenient_flags;
3737
uint8_t upgrade;
38-
uint16_t status_code;
3938
uint8_t finish;
39+
uint16_t flags;
40+
uint16_t status_code;
4041
void* settings;
4142
};
4243

@@ -78,7 +79,8 @@ enum llhttp_errno {
7879
HPE_CB_CHUNK_COMPLETE = 20,
7980
HPE_PAUSED = 21,
8081
HPE_PAUSED_UPGRADE = 22,
81-
HPE_USER = 23
82+
HPE_PAUSED_H2_UPGRADE = 23,
83+
HPE_USER = 24
8284
};
8385
typedef enum llhttp_errno llhttp_errno_t;
8486

@@ -91,11 +93,17 @@ enum llhttp_flags {
9193
F_CONTENT_LENGTH = 0x20,
9294
F_SKIPBODY = 0x40,
9395
F_TRAILING = 0x80,
94-
F_LENIENT = 0x100,
9596
F_TRANSFER_ENCODING = 0x200
9697
};
9798
typedef enum llhttp_flags llhttp_flags_t;
9899

100+
enum llhttp_lenient_flags {
101+
LENIENT_HEADERS = 0x1,
102+
LENIENT_CHUNKED_LENGTH = 0x2,
103+
LENIENT_KEEP_ALIVE = 0x4
104+
};
105+
typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
106+
99107
enum llhttp_type {
100108
HTTP_BOTH = 0,
101109
HTTP_REQUEST = 1,
@@ -145,7 +153,18 @@ enum llhttp_method {
145153
HTTP_LINK = 31,
146154
HTTP_UNLINK = 32,
147155
HTTP_SOURCE = 33,
148-
HTTP_PRI = 34
156+
HTTP_PRI = 34,
157+
HTTP_DESCRIBE = 35,
158+
HTTP_ANNOUNCE = 36,
159+
HTTP_SETUP = 37,
160+
HTTP_PLAY = 38,
161+
HTTP_PAUSE = 39,
162+
HTTP_TEARDOWN = 40,
163+
HTTP_GET_PARAMETER = 41,
164+
HTTP_SET_PARAMETER = 42,
165+
HTTP_REDIRECT = 43,
166+
HTTP_RECORD = 44,
167+
HTTP_FLUSH = 45
149168
};
150169
typedef enum llhttp_method llhttp_method_t;
151170

@@ -173,7 +192,8 @@ typedef enum llhttp_method llhttp_method_t;
173192
XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
174193
XX(21, PAUSED, PAUSED) \
175194
XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
176-
XX(23, USER, USER) \
195+
XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \
196+
XX(24, USER, USER) \
177197

178198

179199
#define HTTP_METHOD_MAP(XX) \
@@ -212,6 +232,17 @@ typedef enum llhttp_method llhttp_method_t;
212232
XX(32, UNLINK, UNLINK) \
213233
XX(33, SOURCE, SOURCE) \
214234
XX(34, PRI, PRI) \
235+
XX(35, DESCRIBE, DESCRIBE) \
236+
XX(36, ANNOUNCE, ANNOUNCE) \
237+
XX(37, SETUP, SETUP) \
238+
XX(38, PLAY, PLAY) \
239+
XX(39, PAUSE, PAUSE) \
240+
XX(40, TEARDOWN, TEARDOWN) \
241+
XX(41, GET_PARAMETER, GET_PARAMETER) \
242+
XX(42, SET_PARAMETER, SET_PARAMETER) \
243+
XX(43, REDIRECT, REDIRECT) \
244+
XX(44, RECORD, RECORD) \
245+
XX(45, FLUSH, FLUSH) \
215246

216247

217248

@@ -227,6 +258,12 @@ extern "C" {
227258
#endif
228259
#include <stddef.h>
229260

261+
#if defined(__wasm__)
262+
#define LLHTTP_EXPORT __attribute__((visibility("default")))
263+
#else
264+
#define LLHTTP_EXPORT
265+
#endif
266+
230267
typedef llhttp__internal_t llhttp_t;
231268
typedef struct llhttp_settings_s llhttp_settings_t;
232269

@@ -264,13 +301,59 @@ struct llhttp_settings_s {
264301
*/
265302
llhttp_cb on_chunk_header;
266303
llhttp_cb on_chunk_complete;
304+
305+
llhttp_cb on_url_complete;
306+
llhttp_cb on_status_complete;
307+
llhttp_cb on_header_field_complete;
308+
llhttp_cb on_header_value_complete;
267309
};
268310

269-
/* Initialize the parser with specific type and user settings */
311+
/* Initialize the parser with specific type and user settings.
312+
*
313+
* NOTE: lifetime of `settings` has to be at least the same as the lifetime of
314+
* the `parser` here. In practice, `settings` has to be either a static
315+
* variable or be allocated with `malloc`, `new`, etc.
316+
*/
317+
LLHTTP_EXPORT
270318
void llhttp_init(llhttp_t* parser, llhttp_type_t type,
271319
const llhttp_settings_t* settings);
272320

321+
#if defined(__wasm__)
322+
323+
LLHTTP_EXPORT
324+
llhttp_t* llhttp_alloc(llhttp_type_t type);
325+
326+
LLHTTP_EXPORT
327+
void llhttp_free(llhttp_t* parser);
328+
329+
LLHTTP_EXPORT
330+
uint8_t llhttp_get_type(llhttp_t* parser);
331+
332+
LLHTTP_EXPORT
333+
uint8_t llhttp_get_http_major(llhttp_t* parser);
334+
335+
LLHTTP_EXPORT
336+
uint8_t llhttp_get_http_minor(llhttp_t* parser);
337+
338+
LLHTTP_EXPORT
339+
uint8_t llhttp_get_method(llhttp_t* parser);
340+
341+
LLHTTP_EXPORT
342+
int llhttp_get_status_code(llhttp_t* parser);
343+
344+
LLHTTP_EXPORT
345+
uint8_t llhttp_get_upgrade(llhttp_t* parser);
346+
347+
#endif // defined(__wasm__)
348+
349+
/* Reset an already initialized parser back to the start state, preserving the
350+
* existing parser type, callback settings, user data, and lenient flags.
351+
*/
352+
LLHTTP_EXPORT
353+
void llhttp_reset(llhttp_t* parser);
354+
273355
/* Initialize the settings object */
356+
LLHTTP_EXPORT
274357
void llhttp_settings_init(llhttp_settings_t* settings);
275358

276359
/* Parse full or partial request/response, invoking user callbacks along the
@@ -289,6 +372,7 @@ void llhttp_settings_init(llhttp_settings_t* settings);
289372
* to return the same error upon each successive call up until `llhttp_init()`
290373
* is called.
291374
*/
375+
LLHTTP_EXPORT
292376
llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
293377

294378
/* This method should be called when the other side has no further bytes to
@@ -299,16 +383,19 @@ llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
299383
* connection. This method will invoke `on_message_complete()` callback if the
300384
* request was terminated safely. Otherwise a error code would be returned.
301385
*/
386+
LLHTTP_EXPORT
302387
llhttp_errno_t llhttp_finish(llhttp_t* parser);
303388

304389
/* Returns `1` if the incoming message is parsed until the last byte, and has
305390
* to be completed by calling `llhttp_finish()` on EOF
306391
*/
392+
LLHTTP_EXPORT
307393
int llhttp_message_needs_eof(const llhttp_t* parser);
308394

309395
/* Returns `1` if there might be any other messages following the last that was
310396
* successfully parsed.
311397
*/
398+
LLHTTP_EXPORT
312399
int llhttp_should_keep_alive(const llhttp_t* parser);
313400

314401
/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
@@ -317,50 +404,59 @@ int llhttp_should_keep_alive(const llhttp_t* parser);
317404
* Important: do not call this from user callbacks! User callbacks must return
318405
* `HPE_PAUSED` if pausing is required.
319406
*/
407+
LLHTTP_EXPORT
320408
void llhttp_pause(llhttp_t* parser);
321409

322410
/* Might be called to resume the execution after the pause in user's callback.
323411
* See `llhttp_execute()` above for details.
324412
*
325413
* Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
326414
*/
415+
LLHTTP_EXPORT
327416
void llhttp_resume(llhttp_t* parser);
328417

329418
/* Might be called to resume the execution after the pause in user's callback.
330419
* See `llhttp_execute()` above for details.
331420
*
332421
* Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
333422
*/
423+
LLHTTP_EXPORT
334424
void llhttp_resume_after_upgrade(llhttp_t* parser);
335425

336426
/* Returns the latest return error */
427+
LLHTTP_EXPORT
337428
llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
338429

339430
/* Returns the verbal explanation of the latest returned error.
340431
*
341432
* Note: User callback should set error reason when returning the error. See
342433
* `llhttp_set_error_reason()` for details.
343434
*/
435+
LLHTTP_EXPORT
344436
const char* llhttp_get_error_reason(const llhttp_t* parser);
345437

346438
/* Assign verbal description to the returned error. Must be called in user
347439
* callbacks right before returning the errno.
348440
*
349441
* Note: `HPE_USER` error code might be useful in user callbacks.
350442
*/
443+
LLHTTP_EXPORT
351444
void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
352445

353446
/* Returns the pointer to the last parsed byte before the returned error. The
354447
* pointer is relative to the `data` argument of `llhttp_execute()`.
355448
*
356449
* Note: this method might be useful for counting the number of parsed bytes.
357450
*/
451+
LLHTTP_EXPORT
358452
const char* llhttp_get_error_pos(const llhttp_t* parser);
359453

360454
/* Returns textual name of error code */
455+
LLHTTP_EXPORT
361456
const char* llhttp_errno_name(llhttp_errno_t err);
362457

363458
/* Returns textual name of HTTP method */
459+
LLHTTP_EXPORT
364460
const char* llhttp_method_name(llhttp_method_t method);
365461

366462

@@ -373,7 +469,36 @@ const char* llhttp_method_name(llhttp_method_t method);
373469
*
374470
* **(USE AT YOUR OWN RISK)**
375471
*/
376-
void llhttp_set_lenient(llhttp_t* parser, int enabled);
472+
LLHTTP_EXPORT
473+
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
474+
475+
476+
/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and
477+
* `Content-Length` headers (disabled by default).
478+
*
479+
* Normally `llhttp` would error when `Transfer-Encoding` is present in
480+
* conjunction with `Content-Length`. This error is important to prevent HTTP
481+
* request smuggling, but may be less desirable for small number of cases
482+
* involving legacy servers.
483+
*
484+
* **(USE AT YOUR OWN RISK)**
485+
*/
486+
LLHTTP_EXPORT
487+
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
488+
489+
490+
/* Enables/disables lenient handling of `Connection: close` and HTTP/1.0
491+
* requests responses.
492+
*
493+
* Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
494+
* the HTTP request/response after the request/response with `Connection: close`
495+
* and `Content-Length`. This is important to prevent cache poisoning attacks,
496+
* but might interact badly with outdated and insecure clients. With this flag
497+
* the extra request/response will be parsed normally.
498+
*
499+
* **(USE AT YOUR OWN RISK)**
500+
*/
501+
void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled);
377502

378503
#ifdef __cplusplus
379504
} /* extern "C" */

0 commit comments

Comments
 (0)