Fix: use x-total-count header for correct gitea totals (#7227)

This commit is contained in:
shamoon
2026-10-08 10:10:30 -07:00
committed by GitHub
parent fec0f5d8b2
commit 97db55ab36
6 changed files with 61 additions and 39 deletions
+2 -2
View File
@@ -49,7 +49,7 @@ export default async function genericProxyHandler(req, res, map) {
}
}
const [status, contentType, data] = await httpProxy(url, params);
const [status, contentType, data, responseHeaders] = await httpProxy(url, params);
let resultData = data;
@@ -63,7 +63,7 @@ export default async function genericProxyHandler(req, res, map) {
.status(status)
.json({ error: { message: "Invalid data", url: sanitizeErrorURL(url), data: resultData } });
}
if (map) resultData = map(resultData);
if (map) resultData = map(resultData, responseHeaders);
}
if (contentType) res.setHeader("Content-Type", contentType);
+16
View File
@@ -253,4 +253,20 @@ describe("utils/proxy/handlers/generic", () => {
expect(res.statusCode).toBe(200);
expect(res.body).toEqual({ mapped: true });
});
it("passes the response headers to the mapping function", async () => {
getServiceWidget.mockResolvedValue({
type: "testservice",
url: "http://example",
});
httpProxy.mockResolvedValueOnce([200, "application/json", { ok: true }, { "x-total-count": "42" }]);
const req = { method: "GET", query: { group: "g", service: "svc", endpoint: "api", index: "0" } };
const res = createMockRes();
await genericProxyHandler(req, res, (data, headers) => ({ total: headers["x-total-count"] }));
expect(res.statusCode).toBe(200);
expect(res.body).toEqual({ total: "42" });
});
});