Skip to content

Commit

Permalink
fix: Correctly handle 1xx cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShogunPanda committed Sep 13, 2023
1 parent 965628d commit bc758af
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/native/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ 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 == 1)
(
parser->type == HTTP_RESPONSE &&
(parser->status_code == 100 || parser->status_code == 101)
)
) {
/* Exit, the rest of the message is in a different protocol. */
return 1;
Expand All @@ -54,6 +57,8 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
parser->flags & F_SKIPBODY || /* response to a HEAD request */
(
parser->type == HTTP_RESPONSE && (
parser->status_code == 102 || /* Processing */
parser->status_code == 103 || /* Early Hints */
parser->status_code == 204 || /* No Content */
parser->status_code == 304 /* Not Modified */
)
Expand Down
55 changes: 55 additions & 0 deletions test/response/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,58 @@ off=107 len=5 span[body]="hello"
off=114 chunk complete
off=117 chunk header len=0
```


## HTTP 103 first, then 200

<!-- meta={"type": "response"} -->
```http
HTTP/1.1 103 Early Hints
Link: </styles.css>; rel=preload; as=style
HTTP/1.1 200 OK
Date: Wed, 13 Sep 2023 11:09:41 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Content-Length: 17
response content
```

```log
off=0 message begin
off=5 len=3 span[version]="1.1"
off=8 version complete
off=13 len=11 span[status]="Early Hints"
off=26 status complete
off=26 len=4 span[header_field]="Link"
off=31 header_field complete
off=32 len=36 span[header_value]="</styles.css>; rel=preload; as=style"
off=70 header_value complete
off=72 headers complete status=103 v=1/1 flags=0 content_length=0
off=72 message complete
off=72 reset
off=72 message begin
off=77 len=3 span[version]="1.1"
off=80 version complete
off=85 len=2 span[status]="OK"
off=89 status complete
off=89 len=4 span[header_field]="Date"
off=94 header_field complete
off=95 len=29 span[header_value]="Wed, 13 Sep 2023 11:09:41 GMT"
off=126 header_value complete
off=126 len=10 span[header_field]="Connection"
off=137 header_field complete
off=138 len=10 span[header_value]="keep-alive"
off=150 header_value complete
off=150 len=10 span[header_field]="Keep-Alive"
off=161 header_field complete
off=162 len=9 span[header_value]="timeout=5"
off=173 header_value complete
off=173 len=14 span[header_field]="Content-Length"
off=188 header_field complete
off=189 len=2 span[header_value]="17"
off=193 header_value complete
off=195 headers complete status=200 v=1/1 flags=21 content_length=17
off=195 len=16 span[body]="response content"
```

0 comments on commit bc758af

Please sign in to comment.