Skip to content

Commit

Permalink
deps: update llhttp to 2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
BethGriggs authored and sam-github committed Feb 4, 2020
1 parent 07d56e4 commit 8f41e83
Show file tree
Hide file tree
Showing 3 changed files with 419 additions and 235 deletions.
39 changes: 21 additions & 18 deletions deps/llhttp/include/llhttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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) \
Expand Down
30 changes: 29 additions & 1 deletion deps/llhttp/src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 8f41e83

Please sign in to comment.