Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/llhttp/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,16 +685,19 @@ 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)));

n('header_value_discard_lws')
.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.
Expand Down
26 changes: 26 additions & 0 deletions test/request/transfer-encoding.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
Transfer-Encoding header
========================

## Empty `Transfer-Encoding` with `Content-Length`

<!-- meta={"type": "request"} -->
```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
Expand Down
25 changes: 24 additions & 1 deletion test/response/transfer-encoding.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
Transfer-Encoding header
========================

## Empty `Transfer-Encoding` with `Content-Length`

<!-- meta={"type": "response"} -->
```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

<!-- meta={"type": "response"} -->
Expand Down Expand Up @@ -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
```

Loading