MCPcopy Create free account
hub / github.com/angular/dev-infra / processHeader

Function processHeader

github-actions/saucelabs/set-saucelabs-env.js:2112–2185  ·  view source on GitHub ↗
(request, key, val)

Source from the content-addressed store, hash-verified

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 }

Callers 2

constructorMethod · 0.70
addHeaderMethod · 0.70

Calls 3

isValidHTTPTokenFunction · 0.70
isValidHeaderValueFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected