Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handle extra spaces in status line #216

Closed
Closed
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
23 changes: 16 additions & 7 deletions src/llhttp/http.ts
Original file line number Diff line number Diff line change
@@ -32,9 +32,11 @@ const NODES: ReadonlyArray<string> = [
'res_http_dot',
'res_http_minor',
'res_http_end',
'res_after_version',
'res_first_space_after_version',
'res_spaces_after_version',
'res_status_code',
'res_status_code_otherwise',
'res_spaces_before_status',
'res_status_start',
'res_status',
'res_line_almost_done',
@@ -330,13 +332,16 @@ export class HTTP {

n('res_http_end')
.otherwise(this.span.version.end().otherwise(
this.invokePausable('on_version_complete', ERROR.CB_VERSION_COMPLETE, 'res_after_version'),
this.invokePausable('on_version_complete', ERROR.CB_VERSION_COMPLETE, 'res_first_space_after_version'),
));

n('res_after_version')
.match(' ', this.update('status_code', 0, 'res_status_code'))
.otherwise(p.error(ERROR.INVALID_VERSION,
'Expected space after version'));
n('res_first_space_after_version')
.match(' ', n('res_spaces_after_version'))
.otherwise(p.error(ERROR.INVALID_VERSION, 'Expected space after version'));

n('res_spaces_after_version')
.match(' ', n('res_spaces_after_version'))
.otherwise(this.update('status_code', 0, 'res_status_code'));

n('res_status_code')
.select(NUM_MAP, this.mulAdd('status_code', {
@@ -346,14 +351,18 @@ export class HTTP {
.otherwise(n('res_status_code_otherwise'));

n('res_status_code_otherwise')
.match(' ', n('res_status_start'))
.match(' ', n('res_spaces_before_status'))
.peek([ '\r', '\n' ], n('res_status_start'))
.otherwise(p.error(ERROR.INVALID_STATUS, 'Invalid response status'));

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

n('res_spaces_before_status')
.match(' ', n('res_spaces_before_status'))
.otherwise(n('res_status_start'));

n('res_status_start')
.match('\r', n('res_line_almost_done'))
.match('\n', onStatusComplete)
36 changes: 36 additions & 0 deletions test/response/sample.md
Original file line number Diff line number Diff line change
@@ -682,3 +682,39 @@ off=73 header_value complete
off=75 headers complete status=200 v=1/1 flags=20 content_length=0
off=75 message complete
```

### Extra space between HTTP version and status code

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


```

```log
off=0 message begin
off=5 len=3 span[version]="1.1"
off=8 version complete
off=14 len=2 span[status]="OK"
off=18 status complete
off=20 headers complete status=200 v=1/1 flags=0 content_length=0
```

### Extra space between HTTP version, status code and reason

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


```

```log
off=0 message begin
off=5 len=3 span[version]="1.1"
off=8 version complete
off=15 len=2 span[status]="OK"
off=19 status complete
off=21 headers complete status=200 v=1/1 flags=0 content_length=0
```