Code Quality

This commit is contained in:
Reinier Criel 2026-04-01 15:23:25 -07:00
parent 27e77d9b0b
commit 2b1247cf36
2 changed files with 11 additions and 6 deletions

View file

@ -76,7 +76,7 @@ describe("modifyPipInfo", async () => {
}) })
); );
const modified = modifyPipInfoResponse( modifyPipInfoResponse(
body, body,
headers, headers,
"https://pypi.org/pypi/requests/json", "https://pypi.org/pypi/requests/json",

View file

@ -109,9 +109,12 @@ function getRequestPathAndQuery(url) {
/** /**
* @param {NodeJS.Dict<string | string[]>} headers * @param {NodeJS.Dict<string | string[]>} headers
* @returns {void} * @returns {NodeJS.Dict<string | string[]>}
*/ */
function normalizeRewrittenResponseHeaders(headers) { function normalizeRewrittenResponseHeaders(headers) {
/** @type {NodeJS.Dict<string | string[]>} */
const normalizedHeaders = { ...headers };
for (const headerName of Object.keys(headers)) { for (const headerName of Object.keys(headers)) {
const lowerHeaderName = headerName.toLowerCase(); const lowerHeaderName = headerName.toLowerCase();
if ( if (
@ -119,9 +122,11 @@ function normalizeRewrittenResponseHeaders(headers) {
lowerHeaderName === "transfer-encoding" || lowerHeaderName === "transfer-encoding" ||
lowerHeaderName === "content-encoding" lowerHeaderName === "content-encoding"
) { ) {
delete headers[headerName]; delete normalizedHeaders[headerName];
} }
} }
return normalizedHeaders;
} }
/** /**
@ -235,9 +240,9 @@ function createProxyRequest(hostname, port, req, res, requestHandler) {
// For rewritten responses, send the final body uncompressed. // For rewritten responses, send the final body uncompressed.
// This avoids mismatches between upstream compression metadata and the // This avoids mismatches between upstream compression metadata and the
// rewritten payload on the wire. // rewritten payload on the wire.
normalizeRewrittenResponseHeaders(headers); const rewrittenHeaders = normalizeRewrittenResponseHeaders(headers);
headers["content-length"] = String(buffer.byteLength); rewrittenHeaders["content-length"] = String(buffer.byteLength);
res.writeHead(statusCode, headers); res.writeHead(statusCode, rewrittenHeaders);
res.end(buffer); res.end(buffer);
}); });
} else { } else {