diff --git a/src/llhttp/http.ts b/src/llhttp/http.ts index dec2228..7a63e21 100644 --- a/src/llhttp/http.ts +++ b/src/llhttp/http.ts @@ -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', @@ -385,7 +385,7 @@ 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')); @@ -393,16 +393,8 @@ export class HTTP { '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') diff --git a/test/response/invalid.md b/test/response/invalid.md index 879cc27..34f8f15 100644 --- a/test/response/invalid.md +++ b/test/response/invalid.md @@ -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 @@ -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) + + +```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 diff --git a/test/response/sample.md b/test/response/sample.md index dbacb63..9f6d7d8 100644 --- a/test/response/sample.md +++ b/test/response/sample.md @@ -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 - - -```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