From de7a41574824b8274a4f320e2c95ccecc72ada28 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 29 May 2026 23:15:54 +0800 Subject: [PATCH] fix: decode compressed git mirror rpc requests --- scripts/g14-gitops-render.mjs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/g14-gitops-render.mjs b/scripts/g14-gitops-render.mjs index 03f548ed..02652008 100644 --- a/scripts/g14-gitops-render.mjs +++ b/scripts/g14-gitops-render.mjs @@ -2825,6 +2825,7 @@ date -u +%Y-%m-%dT%H:%M:%SZ > /cache/HWLAB.last-sync import { spawn } from "node:child_process"; import { createReadStream, statSync } from "node:fs"; import path from "node:path"; +import { createGunzip, createInflate } from "node:zlib"; const cacheRoot = process.env.GIT_MIRROR_CACHE_ROOT || "/cache"; const port = Number(process.env.PORT || 8080); @@ -2889,6 +2890,14 @@ function pktLine(text) { return ` + "`" + `\${length.toString(16).padStart(4, "0")}\${text}` + "`" + `; } +function requestBodyStream(req) { + const encoding = String(req.headers["content-encoding"] || "identity").toLowerCase(); + if (encoding === "identity" || encoding === "") return req; + if (encoding === "gzip" || encoding === "x-gzip") return req.pipe(createGunzip()); + if (encoding === "deflate") return req.pipe(createInflate()); + throw new Error(` + "`" + `unsupported git upload-pack content-encoding: \${encoding}` + "`" + `); +} + function runUploadPackAdvertisement(repoPath, res) { return new Promise((resolve, reject) => { const child = spawn("git-upload-pack", ["--stateless-rpc", "--advertise-refs", repoPath], { stdio: ["ignore", "pipe", "pipe"] }); @@ -2918,7 +2927,9 @@ function runUploadPackRpc(repoPath, req, res) { else resolve(); }); res.writeHead(200, smartHeaders("application/x-git-upload-pack-result")); - req.pipe(child.stdin); + const body = requestBodyStream(req); + body.on("error", (error) => child.stdin.destroy(error)); + body.pipe(child.stdin); child.stdout.pipe(res); }); }