(request, key, val)
| 444 | } |
| 445 | |
| 446 | function processHeader (request, key, val) { |
| 447 | if (val && (typeof val === 'object' && !Array.isArray(val))) { |
| 448 | throw new InvalidArgumentError(`invalid ${key} header`) |
| 449 | } else if (val === undefined) { |
| 450 | return |
| 451 | } |
| 452 | |
| 453 | let headerName = headerNameLowerCasedRecord[key] |
| 454 | |
| 455 | if (headerName === undefined) { |
| 456 | headerName = key.toLowerCase() |
| 457 | if (headerNameLowerCasedRecord[headerName] === undefined && !isValidHTTPToken(headerName)) { |
| 458 | throw new InvalidArgumentError('invalid header key') |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | if (Array.isArray(val)) { |
| 463 | const arr = [] |
| 464 | for (let i = 0; i < val.length; i++) { |
| 465 | if (typeof val[i] === 'string') { |
| 466 | if (!isValidHeaderValue(val[i])) { |
| 467 | throw new InvalidArgumentError(`invalid ${key} header`) |
| 468 | } |
| 469 | arr.push(val[i]) |
| 470 | } else if (val[i] === null) { |
| 471 | arr.push('') |
| 472 | } else if (typeof val[i] === 'object') { |
| 473 | throw new InvalidArgumentError(`invalid ${key} header`) |
| 474 | } else { |
| 475 | arr.push(`${val[i]}`) |
| 476 | } |
| 477 | } |
| 478 | val = arr |
| 479 | } else if (typeof val === 'string') { |
| 480 | if (!isValidHeaderValue(val)) { |
| 481 | throw new InvalidArgumentError(`invalid ${key} header`) |
| 482 | } |
| 483 | } else if (val === null) { |
| 484 | val = '' |
| 485 | } else { |
| 486 | val = `${val}` |
| 487 | } |
| 488 | |
| 489 | if (headerName === 'host') { |
| 490 | if (request.host !== null) { |
| 491 | throw new InvalidArgumentError('duplicate host header') |
| 492 | } |
| 493 | if (typeof val !== 'string') { |
| 494 | throw new InvalidArgumentError('invalid host header') |
| 495 | } |
| 496 | // Consumed by Client |
| 497 | request.host = val |
| 498 | } else if (headerName === 'content-length') { |
| 499 | if (request.contentLength !== null) { |
| 500 | throw new InvalidArgumentError('duplicate content-length header') |
| 501 | } |
| 502 | if (!isValidContentLengthHeaderValue(val)) { |
| 503 | throw new InvalidArgumentError('invalid content-length header') |
no test coverage detected