From e3cf65231888c93474e7c90106c75a9b975377ca Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Sat, 13 Jun 2026 17:52:49 +0800 Subject: [PATCH] fix: pass git mirror CGI headers (#328) Co-authored-by: Codex --- scripts/src/hwlab-node-control-plane.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/src/hwlab-node-control-plane.ts b/scripts/src/hwlab-node-control-plane.ts index a4c873b7..45825898 100644 --- a/scripts/src/hwlab-node-control-plane.ts +++ b/scripts/src/hwlab-node-control-plane.ts @@ -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),