Skip to content

Commit 312b74f

Browse files
islandryuryuhei shima
andauthored
fix: allow tabs around Content-Length (#810)
Co-authored-by: ryuhei shima <islandryu@ryuheis-Mac-Studio.local>
1 parent c893b86 commit 312b74f

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/llhttp/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ export class HTTP {
782782
.otherwise(n('header_value_content_length_ws'));
783783

784784
n('header_value_content_length_ws')
785-
.match(' ', n('header_value_content_length_ws'))
785+
.match([ ' ', '\t' ], n('header_value_content_length_ws'))
786786
.peek([ '\r', '\n' ],
787787
this.setFlag(FLAGS.CONTENT_LENGTH, 'header_value_otherwise'))
788788
.otherwise(invalidContentLength('Invalid character in Content-Length'));

test/request/content-length.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,33 @@ off=39 header_value complete
314314
off=41 headers complete method=3 v=1/1 flags=20 content_length=42
315315
```
316316

317+
### Tabs in `Content-Length` (surrounding)
318+
319+
<!-- meta={"type": "request"} -->
320+
```http
321+
POST / HTTP/1.1
322+
Content-Length:\t42\t
323+
324+
325+
```
326+
327+
```log
328+
off=0 message begin
329+
off=0 len=4 span[method]="POST"
330+
off=4 method complete
331+
off=5 len=1 span[url]="/"
332+
off=7 url complete
333+
off=7 len=4 span[protocol]="HTTP"
334+
off=11 protocol complete
335+
off=12 len=3 span[version]="1.1"
336+
off=15 version complete
337+
off=17 len=14 span[header_field]="Content-Length"
338+
off=32 header_field complete
339+
off=33 len=5 span[header_value]="42\t "
340+
off=40 header_value complete
341+
off=42 headers complete method=3 v=1/1 flags=20 content_length=42
342+
```
343+
317344
### Spaces in `Content-Length` #2
318345

319346
<!-- meta={"type": "request"} -->

test/response/content-length.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,28 @@ off=80 headers complete status=200 v=1/1 flags=20 content_length=456
164164
off=80 skip body
165165
off=80 message complete
166166
```
167+
168+
## Tabs in `Content-Length` (surrounding)
169+
170+
<!-- meta={"type": "response"} -->
171+
```http
172+
HTTP/1.1 200 OK
173+
Content-Length:\t42\t
174+
175+
176+
```
177+
178+
```log
179+
off=0 message begin
180+
off=0 len=4 span[protocol]="HTTP"
181+
off=4 protocol complete
182+
off=5 len=3 span[version]="1.1"
183+
off=8 version complete
184+
off=13 len=2 span[status]="OK"
185+
off=17 status complete
186+
off=17 len=14 span[header_field]="Content-Length"
187+
off=32 header_field complete
188+
off=33 len=3 span[header_value]="42\t"
189+
off=38 header_value complete
190+
off=40 headers complete status=200 v=1/1 flags=20 content_length=42
191+
```

0 commit comments

Comments
 (0)