Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: Restart the parser on HTTP 100. #254

Merged
merged 1 commit into from
Oct 3, 2023
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
10 changes: 6 additions & 4 deletions src/native/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
(parser->upgrade && (parser->method == HTTP_CONNECT ||
(parser->flags & F_SKIPBODY) || !hasBody)) ||
/* See RFC 2616 section 4.4 - 1xx e.g. Continue */
(
parser->type == HTTP_RESPONSE &&
(parser->status_code == 100 || parser->status_code == 101)
)
(parser->type == HTTP_RESPONSE && parser->status_code == 101)
) {
/* Exit, the rest of the message is in a different protocol. */
return 1;
}

if (parser->type == HTTP_RESPONSE && parser->status_code == 100) {
/* No body, restart as the message is complete */
return 0;
}

/* See RFC 2616 section 4.4 */
if (
parser->flags & F_SKIPBODY || /* response to a HEAD request */
Expand Down
50 changes: 50 additions & 0 deletions test/response/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,56 @@ off=114 chunk complete
off=117 chunk header len=0
```

## HTTP 100 first, then 400

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


HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Content-Length: 14
Date: Fri, 15 Sep 2023 19:47:23 GMT
Server: Python/3.10 aiohttp/4.0.0a2.dev0

404: Not Found
```

```log
off=0 message begin
off=5 len=3 span[version]="1.1"
off=8 version complete
off=13 len=8 span[status]="Continue"
off=23 status complete
off=25 headers complete status=100 v=1/1 flags=0 content_length=0
off=25 message complete
off=27 reset
off=27 message begin
off=32 len=3 span[version]="1.1"
off=35 version complete
off=40 len=9 span[status]="Not Found"
off=51 status complete
off=51 len=12 span[header_field]="Content-Type"
off=64 header_field complete
off=65 len=25 span[header_value]="text/plain; charset=utf-8"
off=92 header_value complete
off=92 len=14 span[header_field]="Content-Length"
off=107 header_field complete
off=108 len=2 span[header_value]="14"
off=112 header_value complete
off=112 len=4 span[header_field]="Date"
off=117 header_field complete
off=118 len=29 span[header_value]="Fri, 15 Sep 2023 19:47:23 GMT"
off=149 header_value complete
off=149 len=6 span[header_field]="Server"
off=156 header_field complete
off=157 len=32 span[header_value]="Python/3.10 aiohttp/4.0.0a2.dev0"
off=191 header_value complete
off=193 headers complete status=404 v=1/1 flags=20 content_length=14
off=193 len=14 span[body]="404: Not Found"
off=207 message complete
```

## HTTP 103 first, then 200

Expand Down