diff --git a/src/llhttp/http.ts b/src/llhttp/http.ts index dec2228..2f49e30 100644 --- a/src/llhttp/http.ts +++ b/src/llhttp/http.ts @@ -685,8 +685,11 @@ export class HTTP { const emptyContentLengthError = p.error( ERROR.INVALID_CONTENT_LENGTH, 'Empty Content-Length'); - const checkContentLengthEmptiness = this.load('header_state', { + const emptyTransferEncodingError = p.error( + ERROR.INVALID_TRANSFER_ENCODING, 'Empty Transfer-Encoding'); + const checkEmptyHeaderValue = this.load('header_state', { [HEADER_STATE.CONTENT_LENGTH]: emptyContentLengthError, + [HEADER_STATE.TRANSFER_ENCODING]: emptyTransferEncodingError, }, this.setHeaderFlags( this.emptySpan(span.headerValue, onHeaderValueComplete))); @@ -694,7 +697,7 @@ export class HTTP { .match([ ' ', '\t' ], this.testLenientFlags(LENIENT_FLAGS.HEADERS, { 1: n('header_value_discard_ws'), }, p.error(ERROR.INVALID_HEADER_TOKEN, 'Invalid header value char'))) - .otherwise(checkContentLengthEmptiness); + .otherwise(checkEmptyHeaderValue); // Multiple `Transfer-Encoding` headers should be treated as one, but with // values separate by a comma. diff --git a/test/request/transfer-encoding.md b/test/request/transfer-encoding.md index 47b2e85..cdb0b2c 100644 --- a/test/request/transfer-encoding.md +++ b/test/request/transfer-encoding.md @@ -1,6 +1,32 @@ Transfer-Encoding header ======================== +## Empty `Transfer-Encoding` with `Content-Length` + + +```http +POST /first HTTP/1.1 +Transfer-Encoding: +Content-Length: 5 + +hello +``` + +```log +off=0 message begin +off=0 len=4 span[method]="POST" +off=4 method complete +off=5 len=6 span[url]="/first" +off=12 url complete +off=12 len=4 span[protocol]="HTTP" +off=16 protocol complete +off=17 len=3 span[version]="1.1" +off=20 version complete +off=22 len=17 span[header_field]="Transfer-Encoding" +off=40 header_field complete +off=42 error code=15 reason="Empty Transfer-Encoding" +``` + ## `chunked` ### Parsing and setting flag diff --git a/test/response/transfer-encoding.md b/test/response/transfer-encoding.md index 1d83c27..ab1562b 100644 --- a/test/response/transfer-encoding.md +++ b/test/response/transfer-encoding.md @@ -1,6 +1,30 @@ Transfer-Encoding header ======================== +## Empty `Transfer-Encoding` with `Content-Length` + + +```http +HTTP/1.1 200 OK +Transfer-Encoding: +Content-Length: 5 + +hello +``` + +```log +off=0 message begin +off=0 len=4 span[protocol]="HTTP" +off=4 protocol complete +off=5 len=3 span[version]="1.1" +off=8 version complete +off=13 len=2 span[status]="OK" +off=17 status complete +off=17 len=17 span[header_field]="Transfer-Encoding" +off=35 header_field complete +off=37 error code=15 reason="Empty Transfer-Encoding" +``` + ## Trailing space on chunked body @@ -427,4 +451,3 @@ off=66 len=1 span[body]=lf off=67 len=1 span[body]=cr off=68 len=1 span[body]=lf ``` -