(request, key, val)
| 2110 | } |
| 2111 | }; |
| 2112 | function processHeader(request, key, val) { |
| 2113 | if (val && (typeof val === "object" && !Array.isArray(val))) { |
| 2114 | throw new InvalidArgumentError(`invalid ${key} header`); |
| 2115 | } else if (val === void 0) { |
| 2116 | return; |
| 2117 | } |
| 2118 | let headerName = headerNameLowerCasedRecord[key]; |
| 2119 | if (headerName === void 0) { |
| 2120 | headerName = key.toLowerCase(); |
| 2121 | if (headerNameLowerCasedRecord[headerName] === void 0 && !isValidHTTPToken(headerName)) { |
| 2122 | throw new InvalidArgumentError("invalid header key"); |
| 2123 | } |
| 2124 | } |
| 2125 | if (Array.isArray(val)) { |
| 2126 | const arr = []; |
| 2127 | for (let i = 0; i < val.length; i++) { |
| 2128 | if (typeof val[i] === "string") { |
| 2129 | if (!isValidHeaderValue(val[i])) { |
| 2130 | throw new InvalidArgumentError(`invalid ${key} header`); |
| 2131 | } |
| 2132 | arr.push(val[i]); |
| 2133 | } else if (val[i] === null) { |
| 2134 | arr.push(""); |
| 2135 | } else if (typeof val[i] === "object") { |
| 2136 | throw new InvalidArgumentError(`invalid ${key} header`); |
| 2137 | } else { |
| 2138 | const str = `${val[i]}`; |
| 2139 | if (!isValidHeaderValue(str)) { |
| 2140 | throw new InvalidArgumentError(`invalid ${key} header`); |
| 2141 | } |
| 2142 | arr.push(str); |
| 2143 | } |
| 2144 | } |
| 2145 | val = arr; |
| 2146 | } else if (typeof val === "string") { |
| 2147 | if (!isValidHeaderValue(val)) { |
| 2148 | throw new InvalidArgumentError(`invalid ${key} header`); |
| 2149 | } |
| 2150 | } else if (val === null) { |
| 2151 | val = ""; |
| 2152 | } else { |
| 2153 | val = `${val}`; |
| 2154 | if (!isValidHeaderValue(val)) { |
| 2155 | throw new InvalidArgumentError(`invalid ${key} header`); |
| 2156 | } |
| 2157 | } |
| 2158 | if (headerName === "host") { |
| 2159 | if (request.host !== null) { |
| 2160 | throw new InvalidArgumentError("duplicate host header"); |
| 2161 | } |
| 2162 | if (typeof val !== "string") { |
| 2163 | throw new InvalidArgumentError("invalid host header"); |
| 2164 | } |
| 2165 | request.host = val; |
| 2166 | } else if (headerName === "content-length") { |
| 2167 | if (request.contentLength !== null) { |
| 2168 | throw new InvalidArgumentError("duplicate content-length header"); |
| 2169 | } |
no test coverage detected