| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8554ff2 commit 7589486
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,8 @@ This project aims to: | |||
| 14 | 14 | * Verifiable | |
| 15 | 15 | * Improving benchmarks where possible | |
| 16 | 16 | ||
| 17 | + More details in [Fedor Indutny's talk at JSConf EU 2019](https://youtu.be/x3k_5Mi66sY) | ||
| 18 | + | ||
| 17 | 19 | ## How? | |
| 18 | 20 | ||
| 19 | 21 | Over time, different approaches for improving [http_parser][0]'s code base | |
@@ -30,11 +32,10 @@ So far llhttp outperforms http_parser: | |||
| 30 | 32 | ||
| 31 | 33 | | | input size | bandwidth | reqs/sec | time | | |
| 32 | 34 | |:----------------|-----------:|-------------:|-----------:|--------:| | |
| 33 | - | **llhttp** _(C)_ | 8192.00 mb | 1497.88 mb/s | 3020458.87 ops/sec | 5.47 s | | ||
| 34 | - | **llhttp** _(bitcode)_ | 8192.00 mb | 1131.75 mb/s | 2282171.24 ops/sec | 7.24 s | | ||
| 35 | + | **llhttp** _(C)_ | 8192.00 mb | 1777.24 mb/s | 3583799.39 ops/sec | 4.61 s | | ||
| 35 | 36 | | **http_parser** | 8192.00 mb | 694.66 mb/s | 1406180.33 req/sec | 11.79 s | | |
| 36 | 37 | ||
| 37 | - llhttp is faster by approximately **116%**. | ||
| 38 | + llhttp is faster by approximately **156%**. | ||
| 38 | 39 | ||
| 39 | 40 | ## Maintenance | |
| 40 | 41 | ||
@@ -77,8 +78,6 @@ settings.on_message_complete = handle_on_message_complete; | |||
| 77 | 78 | */ | |
| 78 | 79 | llhttp_init(&parser, HTTP_BOTH, &settings); | |
| 79 | 80 | ||
| 80 | - /* Use `llhttp_set_type(&parser, HTTP_REQUEST);` to override the mode */ | ||
| 81 | - | ||
| 82 | 81 | /* Parse request! */ | |
| 83 | 82 | const char* request = "GET / HTTP/1.1\r\n\r\n"; | |
| 84 | 83 | int request_len = strlen(request); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,9 @@ | |||
| 1 | 1 | #ifndef INCLUDE_LLHTTP_H_ | |
| 2 | 2 | #define INCLUDE_LLHTTP_H_ | |
| 3 | 3 | ||
| 4 | - #define LLHTTP_VERSION_MAJOR 1 | ||
| 5 | - #define LLHTTP_VERSION_MINOR 1 | ||
| 6 | - #define LLHTTP_VERSION_PATCH 4 | ||
| 4 | + #define LLHTTP_VERSION_MAJOR 2 | ||
| 5 | + #define LLHTTP_VERSION_MINOR 0 | ||
| 6 | + #define LLHTTP_VERSION_PATCH 1 | ||
| 7 | 7 | ||
| 8 | 8 | #ifndef INCLUDE_LLHTTP_ITSELF_H_ | |
| 9 | 9 | #define INCLUDE_LLHTTP_ITSELF_H_ | |
@@ -29,7 +29,7 @@ struct llhttp__internal_s { | |||
| 29 | 29 | uint8_t http_major; | |
| 30 | 30 | uint8_t http_minor; | |
| 31 | 31 | uint8_t header_state; | |
| 32 | - uint8_t flags; | ||
| 32 | + uint16_t flags; | ||
| 33 | 33 | uint8_t upgrade; | |
| 34 | 34 | uint16_t status_code; | |
| 35 | 35 | uint8_t finish; | |
@@ -85,7 +85,8 @@ enum llhttp_flags { | |||
| 85 | 85 | F_UPGRADE = 0x10, | |
| 86 | 86 | F_CONTENT_LENGTH = 0x20, | |
| 87 | 87 | F_SKIPBODY = 0x40, | |
| 88 | - F_TRAILING = 0x80 | ||
| 88 | + F_TRAILING = 0x80, | ||
| 89 | + F_LENIENT = 0x100 | ||
| 89 | 90 | }; | |
| 90 | 91 | typedef enum llhttp_flags llhttp_flags_t; | |
| 91 | 92 | ||
@@ -297,7 +298,7 @@ llhttp_errno_t llhttp_finish(llhttp_t* parser); | |||
| 297 | 298 | int llhttp_message_needs_eof(const llhttp_t* parser); | |
| 298 | 299 | ||
| 299 | 300 | /* Returns `1` if there might be any other messages following the last that was | |
| 300 | - * successfuly parsed. | ||
| 301 | + * successfully parsed. | ||
| 301 | 302 | */ | |
| 302 | 303 | int llhttp_should_keep_alive(const llhttp_t* parser); | |
| 303 | 304 | ||
@@ -353,6 +354,18 @@ const char* llhttp_errno_name(llhttp_errno_t err); | |||
| 353 | 354 | /* Returns textual name of HTTP method */ | |
| 354 | 355 | const char* llhttp_method_name(llhttp_method_t method); | |
| 355 | 356 | ||
| 357 | + | ||
| 358 | + /* Enables/disables lenient header value parsing (disabled by default). | ||
| 359 | + * | ||
| 360 | + * Lenient parsing disables header value token checks, extending llhttp's | ||
| 361 | + * protocol support to highly non-compliant clients/server. No | ||
| 362 | + * `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when | ||
| 363 | + * lenient parsing is "on". | ||
| 364 | + * | ||
| 365 | + * **(USE AT YOUR OWN RISK)** | ||
| 366 | + */ | ||
| 367 | + void llhttp_set_lenient(llhttp_t* parser, int enabled); | ||
| 368 | + | ||
| 356 | 369 | #ifdef __cplusplus | |
| 357 | 370 | } /* extern "C" */ | |
| 358 | 371 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,6 +127,15 @@ const char* llhttp_method_name(llhttp_method_t method) { | |||
| 127 | 127 | } | |
| 128 | 128 | ||
| 129 | 129 | ||
| 130 | + void llhttp_set_lenient(llhttp_t* parser, int enabled) { | ||
| 131 | + if (enabled) { | ||
| 132 | + parser->flags |= F_LENIENT; | ||
| 133 | + } else { | ||
| 134 | + parser->flags &= ~F_LENIENT; | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + | ||
| 130 | 139 | /* Callbacks */ | |
| 131 | 140 | ||
| 132 | 141 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,9 +74,11 @@ int llhttp__after_message_complete(llhttp_t* parser, const char* p, | |||
| 74 | 74 | int should_keep_alive; | |
| 75 | 75 | ||
| 76 | 76 | should_keep_alive = llhttp_should_keep_alive(parser); | |
| 77 | - parser->flags = 0; | ||
| 78 | 77 | parser->finish = HTTP_FINISH_SAFE; | |
| 79 | 78 | ||
| 79 | + /* Keep `F_LENIENT` flag between messages, but reset every other flag */ | ||
| 80 | + parser->flags &= F_LENIENT; | ||
| 81 | + | ||
| 80 | 82 | /* NOTE: this is ignored in loose parsing mode */ | |
| 81 | 83 | return should_keep_alive; | |
| 82 | 84 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments