fix: pass git mirror CGI headers (#328)
Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user