mirror of
https://github.com/gethomepage/homepage.git
synced 2026-10-17 07:51:44 -07:00
Fix: use x-total-count header for correct gitea totals (#7227)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user