Skip to content

Commit

Permalink
deps: update llhttp to 2.0.1
Browse files Browse the repository at this point in the history
Changelog:

* Optional SSE4.2 support (at compile time)
* Lenient mode of operation

PR-URL: #30553
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
  • Loading branch information
indutny authored and MylesBorins committed Dec 17, 2019
1 parent 8554ff2 commit 7589486
Show file tree
Hide file tree
Showing 5 changed files with 306 additions and 115 deletions.
9 changes: 4 additions & 5 deletions deps/llhttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This project aims to:
* Verifiable
* Improving benchmarks where possible

More details in [Fedor Indutny's talk at JSConf EU 2019](https://youtu.be/x3k_5Mi66sY)

## How?

Over time, different approaches for improving [http_parser][0]'s code base
Expand All @@ -30,11 +32,10 @@ So far llhttp outperforms http_parser:

| | input size | bandwidth | reqs/sec | time |
|:----------------|-----------:|-------------:|-----------:|--------:|
| **llhttp** _(C)_ | 8192.00 mb | 1497.88 mb/s | 3020458.87 ops/sec | 5.47 s |
| **llhttp** _(bitcode)_ | 8192.00 mb | 1131.75 mb/s | 2282171.24 ops/sec | 7.24 s |
| **llhttp** _(C)_ | 8192.00 mb | 1777.24 mb/s | 3583799.39 ops/sec | 4.61 s |
| **http_parser** | 8192.00 mb | 694.66 mb/s | 1406180.33 req/sec | 11.79 s |

llhttp is faster by approximately **116%**.
llhttp is faster by approximately **156%**.

## Maintenance

Expand Down Expand Up @@ -77,8 +78,6 @@ settings.on_message_complete = handle_on_message_complete;
*/
llhttp_init(&parser, HTTP_BOTH, &settings);

/* Use `llhttp_set_type(&parser, HTTP_REQUEST);` to override the mode */

/* Parse request! */
const char* request = "GET / HTTP/1.1\r\n\r\n";
int request_len = strlen(request);
Expand Down
25 changes: 19 additions & 6 deletions deps/llhttp/include/llhttp.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef INCLUDE_LLHTTP_H_
#define INCLUDE_LLHTTP_H_

#define LLHTTP_VERSION_MAJOR 1
#define LLHTTP_VERSION_MINOR 1
#define LLHTTP_VERSION_PATCH 4
#define LLHTTP_VERSION_MAJOR 2
#define LLHTTP_VERSION_MINOR 0
#define LLHTTP_VERSION_PATCH 1

#ifndef INCLUDE_LLHTTP_ITSELF_H_
#define INCLUDE_LLHTTP_ITSELF_H_
Expand All @@ -29,7 +29,7 @@ struct llhttp__internal_s {
uint8_t http_major;
uint8_t http_minor;
uint8_t header_state;
uint8_t flags;
uint16_t flags;
uint8_t upgrade;
uint16_t status_code;
uint8_t finish;
Expand Down Expand Up @@ -85,7 +85,8 @@ enum llhttp_flags {
F_UPGRADE = 0x10,
F_CONTENT_LENGTH = 0x20,
F_SKIPBODY = 0x40,
F_TRAILING = 0x80
F_TRAILING = 0x80,
F_LENIENT = 0x100
};
typedef enum llhttp_flags llhttp_flags_t;

Expand Down Expand Up @@ -297,7 +298,7 @@ llhttp_errno_t llhttp_finish(llhttp_t* parser);
int llhttp_message_needs_eof(const llhttp_t* parser);

/* Returns `1` if there might be any other messages following the last that was
* successfuly parsed.
* successfully parsed.
*/
int llhttp_should_keep_alive(const llhttp_t* parser);

Expand Down Expand Up @@ -353,6 +354,18 @@ const char* llhttp_errno_name(llhttp_errno_t err);
/* Returns textual name of HTTP method */
const char* llhttp_method_name(llhttp_method_t method);


/* Enables/disables lenient header value parsing (disabled by default).
*
* Lenient parsing disables header value token checks, extending llhttp's
* protocol support to highly non-compliant clients/server. No
* `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
* lenient parsing is "on".
*
* **(USE AT YOUR OWN RISK)**
*/
void llhttp_set_lenient(llhttp_t* parser, int enabled);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
9 changes: 9 additions & 0 deletions deps/llhttp/src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ const char* llhttp_method_name(llhttp_method_t method) {
}


void llhttp_set_lenient(llhttp_t* parser, int enabled) {
if (enabled) {
parser->flags |= F_LENIENT;
} else {
parser->flags &= ~F_LENIENT;
}
}


/* Callbacks */


Expand Down
4 changes: 3 additions & 1 deletion deps/llhttp/src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ int llhttp__after_message_complete(llhttp_t* parser, const char* p,
int should_keep_alive;

should_keep_alive = llhttp_should_keep_alive(parser);
parser->flags = 0;
parser->finish = HTTP_FINISH_SAFE;

/* Keep `F_LENIENT` flag between messages, but reset every other flag */
parser->flags &= F_LENIENT;

/* NOTE: this is ignored in loose parsing mode */
return should_keep_alive;
}
Expand Down
Loading

0 comments on commit 7589486

Please sign in to comment.