Skip to content

Commit 8f41e83

Browse files
BethGriggssam-github
authored andcommitted
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>
1 parent 07d56e4 commit 8f41e83

File tree

3 files changed

+419
-235
lines changed

3 files changed

+419
-235
lines changed

deps/llhttp/include/llhttp.h

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

88
#ifndef INCLUDE_LLHTTP_ITSELF_H_
99
#define INCLUDE_LLHTTP_ITSELF_H_
@@ -66,14 +66,15 @@ enum llhttp_errno {
6666
HPE_INVALID_CHUNK_SIZE = 12,
6767
HPE_INVALID_STATUS = 13,
6868
HPE_INVALID_EOF_STATE = 14,
69-
HPE_CB_MESSAGE_BEGIN = 15,
70-
HPE_CB_HEADERS_COMPLETE = 16,
71-
HPE_CB_MESSAGE_COMPLETE = 17,
72-
HPE_CB_CHUNK_HEADER = 18,
73-
HPE_CB_CHUNK_COMPLETE = 19,
74-
HPE_PAUSED = 20,
75-
HPE_PAUSED_UPGRADE = 21,
76-
HPE_USER = 22
69+
HPE_INVALID_TRANSFER_ENCODING = 15,
70+
HPE_CB_MESSAGE_BEGIN = 16,
71+
HPE_CB_HEADERS_COMPLETE = 17,
72+
HPE_CB_MESSAGE_COMPLETE = 18,
73+
HPE_CB_CHUNK_HEADER = 19,
74+
HPE_CB_CHUNK_COMPLETE = 20,
75+
HPE_PAUSED = 21,
76+
HPE_PAUSED_UPGRADE = 22,
77+
HPE_USER = 23
7778
};
7879
typedef enum llhttp_errno llhttp_errno_t;
7980

@@ -86,7 +87,8 @@ enum llhttp_flags {
8687
F_CONTENT_LENGTH = 0x20,
8788
F_SKIPBODY = 0x40,
8889
F_TRAILING = 0x80,
89-
F_LENIENT = 0x100
90+
F_LENIENT = 0x100,
91+
F_TRANSFER_ENCODING = 0x200
9092
};
9193
typedef enum llhttp_flags llhttp_flags_t;
9294

@@ -158,14 +160,15 @@ typedef enum llhttp_method llhttp_method_t;
158160
XX(12, INVALID_CHUNK_SIZE, INVALID_CHUNK_SIZE) \
159161
XX(13, INVALID_STATUS, INVALID_STATUS) \
160162
XX(14, INVALID_EOF_STATE, INVALID_EOF_STATE) \
161-
XX(15, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \
162-
XX(16, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \
163-
XX(17, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \
164-
XX(18, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \
165-
XX(19, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
166-
XX(20, PAUSED, PAUSED) \
167-
XX(21, PAUSED_UPGRADE, PAUSED_UPGRADE) \
168-
XX(22, USER, USER) \
163+
XX(15, INVALID_TRANSFER_ENCODING, INVALID_TRANSFER_ENCODING) \
164+
XX(16, CB_MESSAGE_BEGIN, CB_MESSAGE_BEGIN) \
165+
XX(17, CB_HEADERS_COMPLETE, CB_HEADERS_COMPLETE) \
166+
XX(18, CB_MESSAGE_COMPLETE, CB_MESSAGE_COMPLETE) \
167+
XX(19, CB_CHUNK_HEADER, CB_CHUNK_HEADER) \
168+
XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
169+
XX(21, PAUSED, PAUSED) \
170+
XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
171+
XX(23, USER, USER) \
169172

170173

171174
#define HTTP_METHOD_MAP(XX) \

deps/llhttp/src/http.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ int llhttp__before_headers_complete(llhttp_t* parser, const char* p,
3232
* 2 - chunk_size_start
3333
* 3 - body_identity
3434
* 4 - body_identity_eof
35+
* 5 - invalid transfer-encoding for request
3536
*/
3637
int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
3738
const char* endp) {
@@ -47,8 +48,29 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
4748
if (parser->flags & F_SKIPBODY) {
4849
return 0;
4950
} else if (parser->flags & F_CHUNKED) {
50-
/* chunked encoding - ignore Content-Length header */
51+
/* chunked encoding - ignore Content-Length header, prepare for a chunk */
5152
return 2;
53+
} else if (parser->flags & F_TRANSFER_ENCODING) {
54+
if (parser->type == HTTP_REQUEST && (parser->flags & F_LENIENT) == 0) {
55+
/* RFC 7230 3.3.3 */
56+
57+
/* If a Transfer-Encoding header field
58+
* is present in a request and the chunked transfer coding is not
59+
* the final encoding, the message body length cannot be determined
60+
* reliably; the server MUST respond with the 400 (Bad Request)
61+
* status code and then close the connection.
62+
*/
63+
return 5;
64+
} else {
65+
/* RFC 7230 3.3.3 */
66+
67+
/* If a Transfer-Encoding header field is present in a response and
68+
* the chunked transfer coding is not the final encoding, the
69+
* message body length is determined by reading the connection until
70+
* it is closed by the server.
71+
*/
72+
return 4;
73+
}
5274
} else {
5375
if (!(parser->flags & F_CONTENT_LENGTH)) {
5476
if (!llhttp_message_needs_eof(parser)) {
@@ -97,6 +119,12 @@ int llhttp_message_needs_eof(const llhttp_t* parser) {
97119
return 0;
98120
}
99121

122+
/* RFC 7230 3.3.3, see `llhttp__after_headers_complete` */
123+
if ((parser->flags & F_TRANSFER_ENCODING) &&
124+
(parser->flags & F_CHUNKED) == 0) {
125+
return 1;
126+
}
127+
100128
if (parser->flags & (F_CHUNKED | F_CONTENT_LENGTH)) {
101129
return 0;
102130
}

0 commit comments

Comments
 (0)