MCPcopy
hub / github.com/di-sukharev/opencommit / processHeader

Function processHeader

out/cli.cjs:52767–52819  ·  view source on GitHub ↗
(request3, key, val, skipAppend = false)

Source from the content-addressed store, hash-verified

52765 }
52766 val = val != null ? `${val}` : "";
52767 if (headerCharRegex.exec(val) !== null) {
52768 throw new InvalidArgumentError(`invalid ${key} header`);
52769 }
52770 return skipAppend ? val : `${key}: ${val}\r
52771`;
52772 }
52773 function processHeader(request3, key, val, skipAppend = false) {
52774 if (val && (typeof val === "object" && !Array.isArray(val))) {
52775 throw new InvalidArgumentError(`invalid ${key} header`);
52776 } else if (val === void 0) {
52777 return;
52778 }
52779 if (request3.host === null && key.length === 4 && key.toLowerCase() === "host") {
52780 if (headerCharRegex.exec(val) !== null) {
52781 throw new InvalidArgumentError(`invalid ${key} header`);
52782 }
52783 request3.host = val;
52784 } else if (request3.contentLength === null && key.length === 14 && key.toLowerCase() === "content-length") {
52785 request3.contentLength = parseInt(val, 10);
52786 if (!Number.isFinite(request3.contentLength)) {
52787 throw new InvalidArgumentError("invalid content-length header");
52788 }
52789 } else if (request3.contentType === null && key.length === 12 && key.toLowerCase() === "content-type") {
52790 request3.contentType = val;
52791 if (skipAppend) request3.headers[key] = processHeaderValue(key, val, skipAppend);
52792 else request3.headers += processHeaderValue(key, val);
52793 } else if (key.length === 17 && key.toLowerCase() === "transfer-encoding") {
52794 throw new InvalidArgumentError("invalid transfer-encoding header");
52795 } else if (key.length === 10 && key.toLowerCase() === "connection") {
52796 const value = typeof val === "string" ? val.toLowerCase() : null;
52797 if (value !== "close" && value !== "keep-alive") {
52798 throw new InvalidArgumentError("invalid connection header");
52799 } else if (value === "close") {
52800 request3.reset = true;
52801 }
52802 } else if (key.length === 10 && key.toLowerCase() === "keep-alive") {
52803 throw new InvalidArgumentError("invalid keep-alive header");
52804 } else if (key.length === 7 && key.toLowerCase() === "upgrade") {
52805 throw new InvalidArgumentError("invalid upgrade header");
52806 } else if (key.length === 6 && key.toLowerCase() === "expect") {
52807 throw new NotSupportedError("expect header not supported");
52808 } else if (tokenRegExp.exec(key) === null) {
52809 throw new InvalidArgumentError("invalid header key");
52810 } else {
52811 if (Array.isArray(val)) {
52812 for (let i3 = 0; i3 < val.length; i3++) {
52813 if (skipAppend) {
52814 if (request3.headers[key]) request3.headers[key] += `,${processHeaderValue(key, val[i3], skipAppend)}`;
52815 else request3.headers[key] = processHeaderValue(key, val[i3], skipAppend);
52816 } else {
52817 request3.headers += processHeaderValue(key, val[i3]);
52818 }
52819 }
52820 } else {
52821 if (skipAppend) request3.headers[key] = processHeaderValue(key, val, skipAppend);
52822 else request3.headers += processHeaderValue(key, val);

Callers 3

constructorMethod · 0.85
addHeaderMethod · 0.85
[kHTTP2BuildRequest]Method · 0.85

Calls 3

processHeaderValueFunction · 0.85
toLowerCaseMethod · 0.80
isFiniteMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…