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

Function matchContentType

out/cli.cjs:33534–33565  ·  view source on GitHub ↗
(response, pattern)

Source from the content-addressed store, hash-verified

33532 exports2.HTTPClient = HTTPClient;
33533 var mediaParamSeparator = /\s*;\s*/g;
33534 function matchContentType(response, pattern) {
33535 var _a5;
33536 if (pattern === "*") {
33537 return true;
33538 }
33539 let contentType = ((_a5 = response.headers.get("content-type")) === null || _a5 === void 0 ? void 0 : _a5.trim()) || "application/octet-stream";
33540 contentType = contentType.toLowerCase();
33541 const wantParts = pattern.toLowerCase().trim().split(mediaParamSeparator);
33542 const [wantType = "", ...wantParams] = wantParts;
33543 if (wantType.split("/").length !== 2) {
33544 return false;
33545 }
33546 const gotParts = contentType.split(mediaParamSeparator);
33547 const [gotType = "", ...gotParams] = gotParts;
33548 const [type2 = "", subtype = ""] = gotType.split("/");
33549 if (!type2 || !subtype) {
33550 return false;
33551 }
33552 if (wantType !== "*/*" && gotType !== wantType && `${type2}/*` !== wantType && `*/${subtype}` !== wantType) {
33553 return false;
33554 }
33555 if (gotParams.length < wantParams.length) {
33556 return false;
33557 }
33558 const params = new Set(gotParams);
33559 for (const wantParam of wantParams) {
33560 if (!params.has(wantParam)) {
33561 return false;
33562 }
33563 }
33564 return true;
33565 }
33566 var codeRangeRE = new RegExp("^[0-9]xx$", "i");
33567 function matchStatusCode(response, codes) {
33568 const actual = `${response.status}`;

Callers 1

matchResponseFunction · 0.85

Calls 4

trimMethod · 0.80
toLowerCaseMethod · 0.80
getMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…