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

Function processHeader

github-actions/browserstack/set-browserstack-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 arr.push(`${val[i]}`);
2139 }
2140 }
2141 val = arr;
2142 } else if (typeof val === "string") {
2143 if (!isValidHeaderValue(val)) {
2144 throw new InvalidArgumentError(`invalid ${key} header`);
2145 }
2146 } else if (val === null) {
2147 val = "";
2148 } else {
2149 val = `${val}`;
2150 }
2151 if (headerName === "host") {
2152 if (request.host !== null) {
2153 throw new InvalidArgumentError("duplicate host header");
2154 }
2155 if (typeof val !== "string") {
2156 throw new InvalidArgumentError("invalid host header");
2157 }
2158 request.host = val;
2159 } else if (headerName === "content-length") {
2160 if (request.contentLength !== null) {
2161 throw new InvalidArgumentError("duplicate content-length header");
2162 }
2163 request.contentLength = parseInt(val, 10);
2164 if (!Number.isFinite(request.contentLength)) {
2165 throw new InvalidArgumentError("invalid content-length header");
2166 }
2167 } else if (request.contentType === null && headerName === "content-type") {
2168 request.contentType = val;
2169 request.headers.push(key, val);

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