(request: Request, targetHost = "gitlab-access.cfdata.org")
| 76 | * that after checking a repo grant. |
| 77 | */ |
| 78 | export 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 | } |
no test coverage detected