MCPcopy Index your code
hub / github.com/nodejs/node / processHeader

Function processHeader

deps/undici/undici.js:3046–3125  ·  view source on GitHub ↗
(request, key, val)

Source from the content-addressed store, hash-verified

3044 }
3045 };
3046 function processHeader(request, key, val) {
3047 if (val && (typeof val === "object" && !Array.isArray(val))) {
3048 throw new InvalidArgumentError(`invalid ${key} header`);
3049 } else if (val === void 0) {
3050 return;
3051 }
3052 let headerName = headerNameLowerCasedRecord[key];
3053 if (headerName === void 0) {
3054 headerName = key.toLowerCase();
3055 if (headerNameLowerCasedRecord[headerName] === void 0 && !isValidHTTPToken(headerName)) {
3056 throw new InvalidArgumentError("invalid header key");
3057 }
3058 }
3059 if (Array.isArray(val)) {
3060 const arr = [];
3061 for (let i = 0; i < val.length; i++) {
3062 if (typeof val[i] === "string") {
3063 if (!isValidHeaderValue(val[i])) {
3064 throw new InvalidArgumentError(`invalid ${key} header`);
3065 }
3066 arr.push(val[i]);
3067 } else if (val[i] === null) {
3068 arr.push("");
3069 } else if (typeof val[i] === "object") {
3070 throw new InvalidArgumentError(`invalid ${key} header`);
3071 } else {
3072 arr.push(`${val[i]}`);
3073 }
3074 }
3075 val = arr;
3076 } else if (typeof val === "string") {
3077 if (!isValidHeaderValue(val)) {
3078 throw new InvalidArgumentError(`invalid ${key} header`);
3079 }
3080 } else if (val === null) {
3081 val = "";
3082 } else {
3083 val = `${val}`;
3084 }
3085 if (headerName === "host") {
3086 if (request.host !== null) {
3087 throw new InvalidArgumentError("duplicate host header");
3088 }
3089 if (typeof val !== "string") {
3090 throw new InvalidArgumentError("invalid host header");
3091 }
3092 request.host = val;
3093 } else if (headerName === "content-length") {
3094 if (request.contentLength !== null) {
3095 throw new InvalidArgumentError("duplicate content-length header");
3096 }
3097 if (!isValidContentLengthHeaderValue(val)) {
3098 throw new InvalidArgumentError("invalid content-length header");
3099 }
3100 request.contentLength = parseInt(val, 10);
3101 } else if (request.contentType === null && headerName === "content-type") {
3102 request.contentType = val;
3103 request.headers.push(key, val);

Callers 2

constructorMethod · 0.70
addHeaderMethod · 0.70

Calls 5

isValidHTTPTokenFunction · 0.70
isValidHeaderValueFunction · 0.70
pushMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…