* 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)
| 12146 | * - if called with no arguments returns an object containing all headers. |
| 12147 | */ |
| 12148 | function headersGetter(headers) { |
| 12149 | var headersObj; |
| 12150 | |
| 12151 | return function(name) { |
| 12152 | if (!headersObj) headersObj = parseHeaders(headers); |
| 12153 | |
| 12154 | if (name) { |
| 12155 | var value = headersObj[lowercase(name)]; |
| 12156 | if (value === undefined) { |
| 12157 | value = null; |
| 12158 | } |
| 12159 | return value; |
| 12160 | } |
| 12161 | |
| 12162 | return headersObj; |
| 12163 | }; |
| 12164 | } |
| 12165 | |
| 12166 | |
| 12167 | /** |
no test coverage detected