MCPcopy Create free account
hub / github.com/acoyfellow/cloudbox / normalizeGitLabSmartHttpRequest

Function normalizeGitLabSmartHttpRequest

src/gitlab-egress.ts:78–89  ·  view source on GitHub ↗
(request: Request, targetHost = "gitlab-access.cfdata.org")

Source from the content-addressed store, hash-verified

76 * that after checking a repo grant.
77 */
78export function normalizeGitLabSmartHttpRequest(request: Request, targetHost = "gitlab-access.cfdata.org"): Request {
79 const url = new URL(request.url);
80 const isSmartHttp = /\/(info\/refs|git-upload-pack|git-receive-pack|HEAD|objects\/)/.test(url.pathname)
81 || url.searchParams.get("service")?.startsWith("git-") === true;
82 if (!isSmartHttp) throw new Error("request is not Git smart HTTP transport");
83 if (!url.pathname.includes(".git/")) {
84 const match = url.pathname.match(GIT_SUFFIXES);
85 if (match?.index !== undefined) url.pathname = `${url.pathname.slice(0, match.index)}.git${match[0]}`;
86 }
87 url.hostname = targetHost;
88 return new Request(url.toString(), request);
89}

Callers 2

computerEgressHandlerFunction · 0.90

Calls 1

getMethod · 0.80

Tested by

no test coverage detected