0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 15:06:33 +01:00

deps: update llhttp to 2.0.4

PR-URL: https://github.com/nodejs-private/node-private/pull/199
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
This commit is contained in:
Beth Griggs 2020-02-04 15:17:48 +00:00 committed by Anna Henningsen
parent 861d3f7a61
commit 4c5b8dd7d8
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
3 changed files with 435 additions and 251 deletions

View File

@ -3,7 +3,7 @@
#define LLHTTP_VERSION_MAJOR 2
#define LLHTTP_VERSION_MINOR 0
#define LLHTTP_VERSION_PATCH 1
#define LLHTTP_VERSION_PATCH 4
#ifndef INCLUDE_LLHTTP_ITSELF_H_
#define INCLUDE_LLHTTP_ITSELF_H_
@ -66,14 +66,15 @@ enum llhttp_errno {
HPE_INVALID_CHUNK_SIZE = 12,
HPE_INVALID_STATUS = 13,
HPE_INVALID_EOF_STATE = 14,
HPE_CB_MESSAGE_BEGIN = 15,
HPE_CB_HEADERS_COMPLETE = 16,
HPE_CB_MESSAGE_COMPLETE = 17,
HPE_CB_CHUNK_HEADER = 18,
HPE_CB_CHUNK_COMPLETE = 19,
HPE_PAUSED = 20,
HPE_PAUSED_UPGRADE = 21,
HPE_USER = 22
HPE_INVALID_TRANSFER_ENCODING = 15,
HPE_CB_MESSAGE_BEGIN = 16,
HPE_CB_HEADERS_COMPLETE = 17,
HPE_CB_MESSAGE_COMPLETE = 18,
HPE_CB_CHUNK_HEADER = 19,
HPE_CB_CHUNK_COMPLETE = 20,
HPE_PAUSED = 21,
HPE_PAUSED_UPGRADE = 22,
HPE_USER = 23
};
typedef enum llhttp_errno llhttp_errno_t;
@ -86,7 +87,8 @@ enum llhttp_flags {
F_CONTENT_LENGTH = 0x20,
F_SKIPBODY = 0x40,
F_TRAILING = 0x80,
F_LENIENT = 0x100
F_LENIENT = 0x100,
F_TRANSFER_ENCODING = 0x200
};
typedef enum llhttp_flags llhttp_flags_t;
@ -158,14 +160,15 @@ typedef enum llhttp_method llhttp_method_t;
XX(12, INVALID_CHUNK_SIZE, INVALID_CHUNK_SIZE) \
XX(13, INVALID_STATUS, INVALID_STATUS) \
XX(14, INVALID_EOF_STATE, INVALID_EOF_STATE) \
XX(15, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \
XX(16, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \
XX(17, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \
XX(18, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \
XX(19, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
XX(20, PAUSED, PAUSED) \
XX(21, PAUSED_UPGRADE, PAUSED_UPGRADE) \
XX(22, USER, USER) \
XX(15, INVALID_TRANSFER_ENCODING, INVALID_TRANSFER_ENCODING) \
XX(16, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \
XX(17, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \
XX(18, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \
XX(19, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \
XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
XX(21, PAUSED, PAUSED) \
XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
XX(23, USER, USER) \
#define HTTP_METHOD_MAP(XX) \

View File

@ -32,6 +32,7 @@ int llhttp__before_headers_complete(llhttp_t* parser, const char* p,
* 2 - chunk_size_start
* 3 - body_identity
* 4 - body_identity_eof
* 5 - invalid transfer-encoding for request
*/
int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
const char* endp) {
@ -47,8 +48,29 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
if (parser->flags & F_SKIPBODY) {
return 0;
} else if (parser->flags & F_CHUNKED) {
/* chunked encoding - ignore Content-Length header */
/* chunked encoding - ignore Content-Length header, prepare for a chunk */
return 2;
} else if (parser->flags & F_TRANSFER_ENCODING) {
if (parser->type == HTTP_REQUEST && (parser->flags & F_LENIENT) == 0) {
/* RFC 7230 3.3.3 */
/* If a Transfer-Encoding header field
* is present in a request and the chunked transfer coding is not
* the final encoding, the message body length cannot be determined
* reliably; the server MUST respond with the 400 (Bad Request)
* status code and then close the connection.
*/
return 5;
} else {
/* RFC 7230 3.3.3 */
/* If a Transfer-Encoding header field is present in a response and
* the chunked transfer coding is not the final encoding, the
* message body length is determined by reading the connection until
* it is closed by the server.
*/
return 4;
}
} else {
if (!(parser->flags & F_CONTENT_LENGTH)) {
if (!llhttp_message_needs_eof(parser)) {
@ -97,6 +119,12 @@ int llhttp_message_needs_eof(const llhttp_t* parser) {
return 0;
}
/* RFC 7230 3.3.3, see `llhttp__after_headers_complete` */
if ((parser->flags & F_TRANSFER_ENCODING) &&
(parser->flags & F_CHUNKED) == 0) {
return 1;
}
if (parser->flags & (F_CHUNKED | F_CONTENT_LENGTH)) {
return 0;
}

File diff suppressed because it is too large Load Diff