* 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)
| 11512 | * - if called with no arguments returns an object containing all headers. |
| 11513 | */ |
| 11514 | function headersGetter(headers) { |
| 11515 | var headersObj; |
| 11516 | |
| 11517 | return function(name) { |
| 11518 | if (!headersObj) headersObj = parseHeaders(headers); |
| 11519 | |
| 11520 | if (name) { |
| 11521 | var value = headersObj[lowercase(name)]; |
| 11522 | if (value === undefined) { |
| 11523 | value = null; |
| 11524 | } |
| 11525 | return value; |
| 11526 | } |
| 11527 | |
| 11528 | return headersObj; |
| 11529 | }; |
| 11530 | } |
| 11531 | |
| 11532 | |
| 11533 | /** |
no test coverage detected