mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
More cleanup
This commit is contained in:
parent
e29c11546c
commit
1a811edc95
5 changed files with 201 additions and 78 deletions
|
|
@ -2,7 +2,7 @@ import https from "https";
|
|||
import { generateCertForHost } from "./certUtils.js";
|
||||
import { HttpsProxyAgent } from "https-proxy-agent";
|
||||
import { ui } from "../environment/userInteraction.js";
|
||||
import { gunzipSync, gzipSync } from "zlib";
|
||||
import { gunzipSync } from "zlib";
|
||||
|
||||
/**
|
||||
* @typedef {import("./interceptors/interceptorBuilder.js").Interceptor} Interceptor
|
||||
|
|
@ -107,6 +107,23 @@ function getRequestPathAndQuery(url) {
|
|||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {NodeJS.Dict<string | string[]>} headers
|
||||
* @returns {void}
|
||||
*/
|
||||
function normalizeRewrittenResponseHeaders(headers) {
|
||||
for (const headerName of Object.keys(headers)) {
|
||||
const lowerHeaderName = headerName.toLowerCase();
|
||||
if (
|
||||
lowerHeaderName === "content-length" ||
|
||||
lowerHeaderName === "transfer-encoding" ||
|
||||
lowerHeaderName === "content-encoding"
|
||||
) {
|
||||
delete headers[headerName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("http").IncomingMessage} req
|
||||
* @param {string} hostname
|
||||
|
|
@ -218,17 +235,7 @@ function createProxyRequest(hostname, port, req, res, requestHandler) {
|
|||
// For rewritten responses, send the final body uncompressed.
|
||||
// This avoids mismatches between upstream compression metadata and the
|
||||
// rewritten payload on the wire.
|
||||
for (const headerName of Object.keys(headers)) {
|
||||
const lowerHeaderName = headerName.toLowerCase();
|
||||
if (
|
||||
lowerHeaderName === "content-length" ||
|
||||
lowerHeaderName === "transfer-encoding" ||
|
||||
lowerHeaderName === "content-encoding"
|
||||
) {
|
||||
delete headers[headerName];
|
||||
}
|
||||
}
|
||||
|
||||
normalizeRewrittenResponseHeaders(headers);
|
||||
headers["content-length"] = String(buffer.byteLength);
|
||||
res.writeHead(statusCode, headers);
|
||||
res.end(buffer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue