Skip to content

Commit

Permalink
Fix zero length chunked response regression (#256)
Browse files Browse the repository at this point in the history
* Add test case for zero length chunked response

* add fix

* limit scope

* tidy

* fix test

* fix test
  • Loading branch information
bdraco authored Oct 27, 2023
1 parent 9ab2afc commit 8acaf3c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/native/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
parser->status_code == 102 || /* Processing */
parser->status_code == 103 || /* Early Hints */
parser->status_code == 204 || /* No Content */
parser->status_code == 304 /* Not Modified */
(parser->status_code == 304 &&
!(parser->flags & F_CHUNKED)) /* Not Modified */
)
)
) {
Expand Down
36 changes: 20 additions & 16 deletions test/response/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ off=94 message complete
HTTP/1.1 304 Not Modified
Transfer-Encoding: chunked
0
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Expand All @@ -523,22 +525,24 @@ off=45 header_field complete
off=46 len=7 span[header_value]="chunked"
off=55 header_value complete
off=57 headers complete status=304 v=1/1 flags=208 content_length=0
off=57 message complete
off=57 reset
off=57 message begin
off=62 len=3 span[version]="1.1"
off=65 version complete
off=70 len=2 span[status]="OK"
off=74 status complete
off=74 len=17 span[header_field]="Transfer-Encoding"
off=92 header_field complete
off=93 len=7 span[header_value]="chunked"
off=102 header_value complete
off=104 headers complete status=200 v=1/1 flags=208 content_length=0
off=107 chunk header len=5
off=107 len=5 span[body]="hello"
off=114 chunk complete
off=117 chunk header len=0
off=60 chunk header len=0
off=62 chunk complete
off=62 message complete
off=62 reset
off=62 message begin
off=67 len=3 span[version]="1.1"
off=70 version complete
off=75 len=2 span[status]="OK"
off=79 status complete
off=79 len=17 span[header_field]="Transfer-Encoding"
off=97 header_field complete
off=98 len=7 span[header_value]="chunked"
off=107 header_value complete
off=109 headers complete status=200 v=1/1 flags=208 content_length=0
off=112 chunk header len=5
off=112 len=5 span[body]="hello"
off=119 chunk complete
off=122 chunk header len=0
```

## HTTP 100 first, then 400
Expand Down
27 changes: 27 additions & 0 deletions test/response/transfer-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,30 @@ off=67 len=1 span[body]=cr
off=68 len=1 span[body]=lf
```

## Zero length chunked can be parsed

<!-- meta={"type": "response" } -->
```http
HTTP/1.1 304 Not Modified
Transfer-Encoding: chunked
0
```

```log
off=0 message begin
off=5 len=3 span[version]="1.1"
off=8 version complete
off=13 len=12 span[status]="Not Modified"
off=27 status complete
off=27 len=17 span[header_field]="Transfer-Encoding"
off=45 header_field complete
off=46 len=7 span[header_value]="chunked"
off=55 header_value complete
off=57 headers complete status=304 v=1/1 flags=208 content_length=0
off=60 chunk header len=0
off=62 chunk complete
off=62 message complete
```

0 comments on commit 8acaf3c

Please sign in to comment.