* Returns a function that provides access to parsed headers. * * Headers are lazy parsed when first requested. * @see parseHeaders * * @param {(string|Object)} headers Headers to provide access to. * @returns {function(string=)} Returns a getter function which if called with: * * - if call
(headers)
| 8584 | * - if called with no arguments returns an object containing all headers. |
| 8585 | */ |
| 8586 | function headersGetter(headers) { |
| 8587 | var headersObj = isObject(headers) ? headers : undefined; |
| 8588 | |
| 8589 | return function(name) { |
| 8590 | if (!headersObj) headersObj = parseHeaders(headers); |
| 8591 | |
| 8592 | if (name) { |
| 8593 | var value = headersObj[lowercase(name)]; |
| 8594 | if (value === void 0) { |
| 8595 | value = null; |
| 8596 | } |
| 8597 | return value; |
| 8598 | } |
| 8599 | |
| 8600 | return headersObj; |
| 8601 | }; |
| 8602 | } |
| 8603 | |
| 8604 | |
| 8605 | /** |
no test coverage detected