Skip to content
Open
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
14 changes: 3 additions & 11 deletions src/llhttp/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const NODES = [
'res_status_code_digit_1',
'res_status_code_digit_2',
'res_status_code_digit_3',
'res_status_code_otherwise',
'res_status_trailing_space',
'res_status_start',
'res_status',
'res_line_almost_done',
Expand Down Expand Up @@ -385,24 +385,16 @@ export class HTTP {
n('res_status_code_digit_3')
.select(NUM_MAP, this.mulAdd('status_code', {
overflow: p.error(ERROR.INVALID_STATUS, 'Invalid status code'),
success: 'res_status_code_otherwise',
success: 'res_status_trailing_space',
}))
.otherwise(p.error(ERROR.INVALID_STATUS, 'Invalid status code'));

const onStatusComplete = this.invokePausable(
'on_status_complete', ERROR.CB_STATUS_COMPLETE, n('headers_start'),
);

n('res_status_code_otherwise')
n('res_status_trailing_space')
.match(' ', n('res_status_start'))
.match('\r', n('res_line_almost_done'))
.match(
'\n',
checkIfAllowLFWithoutCR(
onStatusComplete,
p.error(ERROR.INVALID_STATUS, 'Invalid response status'),
),
)
.otherwise(p.error(ERROR.INVALID_STATUS, 'Invalid response status'));

n('res_status_start')
Expand Down
19 changes: 18 additions & 1 deletion test/response/invalid.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ off=5 len=3 span[version]="1.0"
off=8 version complete
off=8 error code=9 reason="Expected space after version"
```
-->

### Tab after HTTP version

Expand Down Expand Up @@ -266,6 +265,24 @@ off=18 status complete
off=20 headers complete status=200 v=1/1 flags=0 content_length=0
```

### No space after status code (no reason)

<!-- meta={"type": "response"} -->
```http
HTTP/1.1 301


```

```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=12 error code=13 reason="Invalid response status"
```

### One-digit status code

<!-- meta={"type": "response"} -->
Expand Down
19 changes: 0 additions & 19 deletions test/response/sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,25 +288,6 @@ off=24 status complete
off=26 headers complete status=404 v=1/1 flags=0 content_length=0
```

## No reason phrase

<!-- meta={"type": "response"} -->
```http
HTTP/1.1 301


```

```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=14 status complete
off=16 headers complete status=301 v=1/1 flags=0 content_length=0
```

## Empty reason phrase after space

<!-- meta={"type": "response"} -->
Expand Down