| 1 |
Content-Length header |
| 2 |
===================== |
| 3 |
|
| 4 |
## `Content-Length` with zeroes |
| 5 |
|
| 6 |
<!-- meta={"type": "request"} --> |
| 7 |
```http |
| 8 |
PUT /url HTTP/1.1 |
| 9 |
Content-Length: 003 |
| 10 |
|
| 11 |
abc |
| 12 |
``` |
| 13 |
|
| 14 |
```log |
| 15 |
off=0 message begin |
| 16 |
off=0 len=3 span[method]="PUT" |
| 17 |
off=3 method complete |
| 18 |
off=4 len=4 span[url]="/url" |
| 19 |
off=9 url complete |
| 20 |
off=14 len=3 span[version]="1.1" |
| 21 |
off=17 version complete |
| 22 |
off=19 len=14 span[header_field]="Content-Length" |
| 23 |
off=34 header_field complete |
| 24 |
off=35 len=3 span[header_value]="003" |
| 25 |
off=40 header_value complete |
| 26 |
off=42 headers complete method=4 v=1/1 flags=20 content_length=3 |
| 27 |
off=42 len=3 span[body]="abc" |
| 28 |
off=45 message complete |
| 29 |
``` |
| 30 |
|
| 31 |
## `Content-Length` with follow-up headers |
| 32 |
|
| 33 |
The way the parser works is that special headers (like `Content-Length`) first |
| 34 |
set `header_state` to appropriate value, and then apply custom parsing using |
| 35 |
that value. For `Content-Length`, in particular, the `header_state` is used for |
| 36 |
setting the flag too. |
| 37 |
|
| 38 |
Make sure that `header_state` is reset to `0`, so that the flag won't be |
| 39 |
attempted to set twice (and error). |
| 40 |
|
| 41 |
<!-- meta={"type": "request"} --> |
| 42 |
```http |
| 43 |
PUT /url HTTP/1.1 |
| 44 |
Content-Length: 003 |
| 45 |
Ohai: world |
| 46 |
|
| 47 |
abc |
| 48 |
``` |
| 49 |
|
| 50 |
```log |
| 51 |
off=0 message begin |
| 52 |
off=0 len=3 span[method]="PUT" |
| 53 |
off=3 method complete |
| 54 |
off=4 len=4 span[url]="/url" |
| 55 |
off=9 url complete |
| 56 |
off=14 len=3 span[version]="1.1" |
| 57 |
off=17 version complete |
| 58 |
off=19 len=14 span[header_field]="Content-Length" |
| 59 |
off=34 header_field complete |
| 60 |
off=35 len=3 span[header_value]="003" |
| 61 |
off=40 header_value complete |
| 62 |
off=40 len=4 span[header_field]="Ohai" |
| 63 |
off=45 header_field complete |
| 64 |
off=46 len=5 span[header_value]="world" |
| 65 |
off=53 header_value complete |
| 66 |
off=55 headers complete method=4 v=1/1 flags=20 content_length=3 |
| 67 |
off=55 len=3 span[body]="abc" |
| 68 |
off=58 message complete |
| 69 |
``` |
| 70 |
|
| 71 |
## Error on `Content-Length` overflow |
| 72 |
|
| 73 |
<!-- meta={"type": "request"} --> |
| 74 |
```http |
| 75 |
PUT /url HTTP/1.1 |
| 76 |
Content-Length: 1000000000000000000000 |
| 77 |
|
| 78 |
``` |
| 79 |
|
| 80 |
```log |
| 81 |
off=0 message begin |
| 82 |
off=0 len=3 span[method]="PUT" |
| 83 |
off=3 method complete |
| 84 |
off=4 len=4 span[url]="/url" |
| 85 |
off=9 url complete |
| 86 |
off=14 len=3 span[version]="1.1" |
| 87 |
off=17 version complete |
| 88 |
off=19 len=14 span[header_field]="Content-Length" |
| 89 |
off=34 header_field complete |
| 90 |
off=35 len=21 span[header_value]="100000000000000000000" |
| 91 |
off=56 error code=11 reason="Content-Length overflow" |
| 92 |
``` |
| 93 |
|
| 94 |
## Error on duplicate `Content-Length` |
| 95 |
|
| 96 |
<!-- meta={"type": "request"} --> |
| 97 |
```http |
| 98 |
PUT /url HTTP/1.1 |
| 99 |
Content-Length: 1 |
| 100 |
Content-Length: 2 |
| 101 |
|
| 102 |
``` |
| 103 |
|
| 104 |
```log |
| 105 |
off=0 message begin |
| 106 |
off=0 len=3 span[method]="PUT" |
| 107 |
off=3 method complete |
| 108 |
off=4 len=4 span[url]="/url" |
| 109 |
off=9 url complete |
| 110 |
off=14 len=3 span[version]="1.1" |
| 111 |
off=17 version complete |
| 112 |
off=19 len=14 span[header_field]="Content-Length" |
| 113 |
off=34 header_field complete |
| 114 |
off=35 len=1 span[header_value]="1" |
| 115 |
off=38 header_value complete |
| 116 |
off=38 len=14 span[header_field]="Content-Length" |
| 117 |
off=53 header_field complete |
| 118 |
off=54 error code=4 reason="Duplicate Content-Length" |
| 119 |
``` |
| 120 |
|
| 121 |
## Error on simultaneous `Content-Length` and `Transfer-Encoding: identity` |
| 122 |
|
| 123 |
<!-- meta={"type": "request"} --> |
| 124 |
```http |
| 125 |
PUT /url HTTP/1.1 |
| 126 |
Content-Length: 1 |
| 127 |
Transfer-Encoding: identity |
| 128 |
|
| 129 |
|
| 130 |
``` |
| 131 |
|
| 132 |
```log |
| 133 |
off=0 message begin |
| 134 |
off=0 len=3 span[method]="PUT" |
| 135 |
off=3 method complete |
| 136 |
off=4 len=4 span[url]="/url" |
| 137 |
off=9 url complete |
| 138 |
off=14 len=3 span[version]="1.1" |
| 139 |
off=17 version complete |
| 140 |
off=19 len=14 span[header_field]="Content-Length" |
| 141 |
off=34 header_field complete |
| 142 |
off=35 len=1 span[header_value]="1" |
| 143 |
off=38 header_value complete |
| 144 |
off=38 len=17 span[header_field]="Transfer-Encoding" |
| 145 |
off=56 header_field complete |
| 146 |
off=56 error code=15 reason="Transfer-Encoding can't be present with Content-Length" |
| 147 |
``` |
| 148 |
|
| 149 |
## Invalid whitespace token with `Content-Length` header field |
| 150 |
|
| 151 |
<!-- meta={"type": "request"} --> |
| 152 |
```http |
| 153 |
PUT /url HTTP/1.1 |
| 154 |
Connection: upgrade |
| 155 |
Content-Length : 4 |
| 156 |
Upgrade: ws |
| 157 |
|
| 158 |
abcdefgh |
| 159 |
``` |
| 160 |
|
| 161 |
```log |
| 162 |
off=0 message begin |
| 163 |
off=0 len=3 span[method]="PUT" |
| 164 |
off=3 method complete |
| 165 |
off=4 len=4 span[url]="/url" |
| 166 |
off=9 url complete |
| 167 |
off=14 len=3 span[version]="1.1" |
| 168 |
off=17 version complete |
| 169 |
off=19 len=10 span[header_field]="Connection" |
| 170 |
off=30 header_field complete |
| 171 |
off=31 len=7 span[header_value]="upgrade" |
| 172 |
off=40 header_value complete |
| 173 |
off=40 len=14 span[header_field]="Content-Length" |
| 174 |
off=55 error code=10 reason="Invalid header field char" |
| 175 |
``` |
| 176 |
|
| 177 |
## Invalid whitespace token with `Content-Length` header field (lenient) |
| 178 |
|
| 179 |
<!-- meta={"type": "request-lenient-headers"} --> |
| 180 |
```http |
| 181 |
PUT /url HTTP/1.1 |
| 182 |
Connection: upgrade |
| 183 |
Content-Length : 4 |
| 184 |
Upgrade: ws |
| 185 |
|
| 186 |
abcdefgh |
| 187 |
``` |
| 188 |
|
| 189 |
```log |
| 190 |
off=0 message begin |
| 191 |
off=0 len=3 span[method]="PUT" |
| 192 |
off=3 method complete |
| 193 |
off=4 len=4 span[url]="/url" |
| 194 |
off=9 url complete |
| 195 |
off=14 len=3 span[version]="1.1" |
| 196 |
off=17 version complete |
| 197 |
off=19 len=10 span[header_field]="Connection" |
| 198 |
off=30 header_field complete |
| 199 |
off=31 len=7 span[header_value]="upgrade" |
| 200 |
off=40 header_value complete |
| 201 |
off=40 len=15 span[header_field]="Content-Length " |
| 202 |
off=56 header_field complete |
| 203 |
off=57 len=1 span[header_value]="4" |
| 204 |
off=60 header_value complete |
| 205 |
off=60 len=7 span[header_field]="Upgrade" |
| 206 |
off=68 header_field complete |
| 207 |
off=69 len=2 span[header_value]="ws" |
| 208 |
off=73 header_value complete |
| 209 |
off=75 headers complete method=4 v=1/1 flags=34 content_length=4 |
| 210 |
off=75 len=4 span[body]="abcd" |
| 211 |
off=79 message complete |
| 212 |
off=79 error code=22 reason="Pause on CONNECT/Upgrade" |
| 213 |
``` |
| 214 |
|
| 215 |
## No error on simultaneous `Content-Length` and `Transfer-Encoding: identity` (lenient) |
| 216 |
|
| 217 |
<!-- meta={"type": "request-lenient-chunked-length"} --> |
| 218 |
```http |
| 219 |
PUT /url HTTP/1.1 |
| 220 |
Content-Length: 1 |
| 221 |
Transfer-Encoding: identity |
| 222 |
|
| 223 |
|
| 224 |
``` |
| 225 |
|
| 226 |
```log |
| 227 |
off=0 message begin |
| 228 |
off=0 len=3 span[method]="PUT" |
| 229 |
off=3 method complete |
| 230 |
off=4 len=4 span[url]="/url" |
| 231 |
off=9 url complete |
| 232 |
off=14 len=3 span[version]="1.1" |
| 233 |
off=17 version complete |
| 234 |
off=19 len=14 span[header_field]="Content-Length" |
| 235 |
off=34 header_field complete |
| 236 |
off=35 len=1 span[header_value]="1" |
| 237 |
off=38 header_value complete |
| 238 |
off=38 len=17 span[header_field]="Transfer-Encoding" |
| 239 |
off=56 header_field complete |
| 240 |
off=57 len=8 span[header_value]="identity" |
| 241 |
off=67 header_value complete |
| 242 |
off=69 headers complete method=4 v=1/1 flags=220 content_length=1 |
| 243 |
``` |
| 244 |
|
| 245 |
## Funky `Content-Length` with body |
| 246 |
|
| 247 |
<!-- meta={"type": "request"} --> |
| 248 |
```http |
| 249 |
GET /get_funky_content_length_body_hello HTTP/1.0 |
| 250 |
conTENT-Length: 5 |
| 251 |
|
| 252 |
HELLO |
| 253 |
``` |
| 254 |
|
| 255 |
```log |
| 256 |
off=0 message begin |
| 257 |
off=0 len=3 span[method]="GET" |
| 258 |
off=3 method complete |
| 259 |
off=4 len=36 span[url]="/get_funky_content_length_body_hello" |
| 260 |
off=41 url complete |
| 261 |
off=46 len=3 span[version]="1.0" |
| 262 |
off=49 version complete |
| 263 |
off=51 len=14 span[header_field]="conTENT-Length" |
| 264 |
off=66 header_field complete |
| 265 |
off=67 len=1 span[header_value]="5" |
| 266 |
off=70 header_value complete |
| 267 |
off=72 headers complete method=1 v=1/0 flags=20 content_length=5 |
| 268 |
off=72 len=5 span[body]="HELLO" |
| 269 |
off=77 message complete |
| 270 |
``` |
| 271 |
|
| 272 |
## Spaces in `Content-Length` (surrounding) |
| 273 |
|
| 274 |
<!-- meta={"type": "request"} --> |
| 275 |
```http |
| 276 |
POST / HTTP/1.1 |
| 277 |
Content-Length: 42 |
| 278 |
|
| 279 |
|
| 280 |
``` |
| 281 |
|
| 282 |
```log |
| 283 |
off=0 message begin |
| 284 |
off=0 len=4 span[method]="POST" |
| 285 |
off=4 method complete |
| 286 |
off=5 len=1 span[url]="/" |
| 287 |
off=7 url complete |
| 288 |
off=12 len=3 span[version]="1.1" |
| 289 |
off=15 version complete |
| 290 |
off=17 len=14 span[header_field]="Content-Length" |
| 291 |
off=32 header_field complete |
| 292 |
off=34 len=3 span[header_value]="42 " |
| 293 |
off=39 header_value complete |
| 294 |
off=41 headers complete method=3 v=1/1 flags=20 content_length=42 |
| 295 |
``` |
| 296 |
|
| 297 |
### Spaces in `Content-Length` #2 |
| 298 |
|
| 299 |
<!-- meta={"type": "request"} --> |
| 300 |
```http |
| 301 |
POST / HTTP/1.1 |
| 302 |
Content-Length: 4 2 |
| 303 |
|
| 304 |
|
| 305 |
``` |
| 306 |
|
| 307 |
```log |
| 308 |
off=0 message begin |
| 309 |
off=0 len=4 span[method]="POST" |
| 310 |
off=4 method complete |
| 311 |
off=5 len=1 span[url]="/" |
| 312 |
off=7 url complete |
| 313 |
off=12 len=3 span[version]="1.1" |
| 314 |
off=15 version complete |
| 315 |
off=17 len=14 span[header_field]="Content-Length" |
| 316 |
off=32 header_field complete |
| 317 |
off=33 len=2 span[header_value]="4 " |
| 318 |
off=35 error code=11 reason="Invalid character in Content-Length" |
| 319 |
``` |
| 320 |
|
| 321 |
### Spaces in `Content-Length` #3 |
| 322 |
|
| 323 |
<!-- meta={"type": "request"} --> |
| 324 |
```http |
| 325 |
POST / HTTP/1.1 |
| 326 |
Content-Length: 13 37 |
| 327 |
|
| 328 |
|
| 329 |
``` |
| 330 |
|
| 331 |
```log |
| 332 |
off=0 message begin |
| 333 |
off=0 len=4 span[method]="POST" |
| 334 |
off=4 method complete |
| 335 |
off=5 len=1 span[url]="/" |
| 336 |
off=7 url complete |
| 337 |
off=12 len=3 span[version]="1.1" |
| 338 |
off=15 version complete |
| 339 |
off=17 len=14 span[header_field]="Content-Length" |
| 340 |
off=32 header_field complete |
| 341 |
off=33 len=3 span[header_value]="13 " |
| 342 |
off=36 error code=11 reason="Invalid character in Content-Length" |
| 343 |
``` |
| 344 |
|
| 345 |
### Empty `Content-Length` |
| 346 |
|
| 347 |
<!-- meta={"type": "request"} --> |
| 348 |
```http |
| 349 |
POST / HTTP/1.1 |
| 350 |
Content-Length: |
| 351 |
|
| 352 |
|
| 353 |
``` |
| 354 |
|
| 355 |
```log |
| 356 |
off=0 message begin |
| 357 |
off=0 len=4 span[method]="POST" |
| 358 |
off=4 method complete |
| 359 |
off=5 len=1 span[url]="/" |
| 360 |
off=7 url complete |
| 361 |
off=12 len=3 span[version]="1.1" |
| 362 |
off=15 version complete |
| 363 |
off=17 len=14 span[header_field]="Content-Length" |
| 364 |
off=32 header_field complete |
| 365 |
off=34 error code=11 reason="Empty Content-Length" |
| 366 |
``` |
| 367 |
|
| 368 |
## `Content-Length` with CR instead of dash |
| 369 |
|
| 370 |
<!-- meta={"type": "request", "noScan": true} --> |
| 371 |
```http |
| 372 |
PUT /url HTTP/1.1 |
| 373 |
Content\rLength: 003 |
| 374 |
|
| 375 |
abc |
| 376 |
``` |
| 377 |
|
| 378 |
```log |
| 379 |
off=0 message begin |
| 380 |
off=0 len=3 span[method]="PUT" |
| 381 |
off=3 method complete |
| 382 |
off=4 len=4 span[url]="/url" |
| 383 |
off=9 url complete |
| 384 |
off=14 len=3 span[version]="1.1" |
| 385 |
off=17 version complete |
| 386 |
off=26 error code=10 reason="Invalid header token" |
| 387 |
``` |
| 388 |
|
| 389 |
## Content-Length reset when no body is received |
| 390 |
|
| 391 |
<!-- meta={"type": "request", "skipBody": true} --> |
| 392 |
```http |
| 393 |
PUT /url HTTP/1.1 |
| 394 |
Content-Length: 123 |
| 395 |
|
| 396 |
POST /url HTTP/1.1 |
| 397 |
Content-Length: 456 |
| 398 |
|
| 399 |
|
| 400 |
``` |
| 401 |
|
| 402 |
```log |
| 403 |
off=0 message begin |
| 404 |
off=0 len=3 span[method]="PUT" |
| 405 |
off=3 method complete |
| 406 |
off=4 len=4 span[url]="/url" |
| 407 |
off=9 url complete |
| 408 |
off=14 len=3 span[version]="1.1" |
| 409 |
off=17 version complete |
| 410 |
off=19 len=14 span[header_field]="Content-Length" |
| 411 |
off=34 header_field complete |
| 412 |
off=35 len=3 span[header_value]="123" |
| 413 |
off=40 header_value complete |
| 414 |
off=42 headers complete method=4 v=1/1 flags=20 content_length=123 |
| 415 |
off=42 skip body |
| 416 |
off=42 message complete |
| 417 |
off=42 reset |
| 418 |
off=42 message begin |
| 419 |
off=42 len=4 span[method]="POST" |
| 420 |
off=46 method complete |
| 421 |
off=47 len=4 span[url]="/url" |
| 422 |
off=52 url complete |
| 423 |
off=57 len=3 span[version]="1.1" |
| 424 |
off=60 version complete |
| 425 |
off=62 len=14 span[header_field]="Content-Length" |
| 426 |
off=77 header_field complete |
| 427 |
off=78 len=3 span[header_value]="456" |
| 428 |
off=83 header_value complete |
| 429 |
off=85 headers complete method=3 v=1/1 flags=20 content_length=456 |
| 430 |
off=85 skip body |
| 431 |
off=85 message complete |
| 432 |
``` |
| 433 |
|
| 434 |
## Missing CRLF-CRLF before body |
| 435 |
|
| 436 |
<!-- meta={"type": "request" } --> |
| 437 |
```http |
| 438 |
PUT /url HTTP/1.1 |
| 439 |
Content-Length: 3 |
| 440 |
\rabc |
| 441 |
``` |
| 442 |
|
| 443 |
```log |
| 444 |
off=0 message begin |
| 445 |
off=0 len=3 span[method]="PUT" |
| 446 |
off=3 method complete |
| 447 |
off=4 len=4 span[url]="/url" |
| 448 |
off=9 url complete |
| 449 |
off=14 len=3 span[version]="1.1" |
| 450 |
off=17 version complete |
| 451 |
off=19 len=14 span[header_field]="Content-Length" |
| 452 |
off=34 header_field complete |
| 453 |
off=35 len=1 span[header_value]="3" |
| 454 |
off=38 header_value complete |
| 455 |
off=39 error code=2 reason="Expected LF after headers" |
| 456 |
``` |
| 457 |
|
| 458 |
## Missing CRLF-CRLF before body (lenient) |
| 459 |
|
| 460 |
<!-- meta={"type": "request-lenient-optional-lf-after-cr" } --> |
| 461 |
```http |
| 462 |
PUT /url HTTP/1.1 |
| 463 |
Content-Length: 3 |
| 464 |
\rabc |
| 465 |
``` |
| 466 |
|
| 467 |
```log |
| 468 |
off=0 message begin |
| 469 |
off=0 len=3 span[method]="PUT" |
| 470 |
off=3 method complete |
| 471 |
off=4 len=4 span[url]="/url" |
| 472 |
off=9 url complete |
| 473 |
off=14 len=3 span[version]="1.1" |
| 474 |
off=17 version complete |
| 475 |
off=19 len=14 span[header_field]="Content-Length" |
| 476 |
off=34 header_field complete |
| 477 |
off=35 len=1 span[header_value]="3" |
| 478 |
off=38 header_value complete |
| 479 |
off=39 headers complete method=4 v=1/1 flags=20 content_length=3 |
| 480 |
off=39 len=3 span[body]="abc" |
| 481 |
off=42 message complete |
| 482 |
``` |