Skip to content

Commit 8acaf3c

Browse files
authored
Fix zero length chunked response regression (#256)
* Add test case for zero length chunked response * add fix * limit scope * tidy * fix test * fix test
1 parent 9ab2afc commit 8acaf3c

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

src/native/http.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
6262
parser->status_code == 102 || /* Processing */
6363
parser->status_code == 103 || /* Early Hints */
6464
parser->status_code == 204 || /* No Content */
65-
parser->status_code == 304 /* Not Modified */
65+
(parser->status_code == 304 &&
66+
!(parser->flags & F_CHUNKED)) /* Not Modified */
6667
)
6768
)
6869
) {

test/response/connection.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ off=94 message complete
503503
HTTP/1.1 304 Not Modified
504504
Transfer-Encoding: chunked
505505
506+
0
507+
506508
HTTP/1.1 200 OK
507509
Transfer-Encoding: chunked
508510
@@ -523,22 +525,24 @@ off=45 header_field complete
523525
off=46 len=7 span[header_value]="chunked"
524526
off=55 header_value complete
525527
off=57 headers complete status=304 v=1/1 flags=208 content_length=0
526-
off=57 message complete
527-
off=57 reset
528-
off=57 message begin
529-
off=62 len=3 span[version]="1.1"
530-
off=65 version complete
531-
off=70 len=2 span[status]="OK"
532-
off=74 status complete
533-
off=74 len=17 span[header_field]="Transfer-Encoding"
534-
off=92 header_field complete
535-
off=93 len=7 span[header_value]="chunked"
536-
off=102 header_value complete
537-
off=104 headers complete status=200 v=1/1 flags=208 content_length=0
538-
off=107 chunk header len=5
539-
off=107 len=5 span[body]="hello"
540-
off=114 chunk complete
541-
off=117 chunk header len=0
528+
off=60 chunk header len=0
529+
off=62 chunk complete
530+
off=62 message complete
531+
off=62 reset
532+
off=62 message begin
533+
off=67 len=3 span[version]="1.1"
534+
off=70 version complete
535+
off=75 len=2 span[status]="OK"
536+
off=79 status complete
537+
off=79 len=17 span[header_field]="Transfer-Encoding"
538+
off=97 header_field complete
539+
off=98 len=7 span[header_value]="chunked"
540+
off=107 header_value complete
541+
off=109 headers complete status=200 v=1/1 flags=208 content_length=0
542+
off=112 chunk header len=5
543+
off=112 len=5 span[body]="hello"
544+
off=119 chunk complete
545+
off=122 chunk header len=0
542546
```
543547

544548
## HTTP 100 first, then 400

test/response/transfer-encoding.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,30 @@ off=67 len=1 span[body]=cr
408408
off=68 len=1 span[body]=lf
409409
```
410410

411+
## Zero length chunked can be parsed
412+
413+
<!-- meta={"type": "response" } -->
414+
```http
415+
HTTP/1.1 304 Not Modified
416+
Transfer-Encoding: chunked
417+
418+
0
419+
420+
421+
```
422+
423+
```log
424+
off=0 message begin
425+
off=5 len=3 span[version]="1.1"
426+
off=8 version complete
427+
off=13 len=12 span[status]="Not Modified"
428+
off=27 status complete
429+
off=27 len=17 span[header_field]="Transfer-Encoding"
430+
off=45 header_field complete
431+
off=46 len=7 span[header_value]="chunked"
432+
off=55 header_value complete
433+
off=57 headers complete status=304 v=1/1 flags=208 content_length=0
434+
off=60 chunk header len=0
435+
off=62 chunk complete
436+
off=62 message complete
437+
```

0 commit comments

Comments
 (0)