fix: pass git mirror CGI headers (#328)

Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
Lyon
2026-06-13 17:52:49 +08:00
committed by GitHub
parent 4e7c10d132
commit e3cf652318
+14
View File
@@ -954,10 +954,24 @@ function parseHeaders(buffer) {
return { status, headers, rest };
}
function cgiHeaderEnv(req) {
const env = {};
for (const [key, value] of Object.entries(req.headers)) {
if (value === undefined) continue;
const joined = Array.isArray(value) ? value.join(', ') : String(value);
const normalized = key.toUpperCase().replace(/-/g, '_');
if (normalized === 'CONTENT_TYPE') env.CONTENT_TYPE = joined;
else if (normalized === 'CONTENT_LENGTH') env.CONTENT_LENGTH = joined;
else env['HTTP_' + normalized] = joined;
}
return env;
}
function handleGit(req, res) {
const url = new URL(req.url || '/', 'http://git-mirror.local');
const env = {
...process.env,
...cgiHeaderEnv(req),
GIT_PROJECT_ROOT: projectRoot,
GIT_HTTP_EXPORT_ALL: '1',
PATH_INFO: decodeURIComponent(url.pathname),