Skip to content

Commit 18db30e

Browse files
authored
fix(proxy): strip hop-by-hop response headers (#6)
1 parent 15a55b1 commit 18db30e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/proxy.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ const HOP_BY_HOP = new Set([
66
"proxy-authorization", "te", "trailer", "transfer-encoding", "upgrade", "content-length",
77
]);
88

9+
function filterResponseHeaders(headers: Headers): [string, string][] {
10+
const result: [string, string][] = [];
11+
12+
for (const [name, value] of headers.entries()) {
13+
if (!HOP_BY_HOP.has(name.toLowerCase())) {
14+
result.push([name, value]);
15+
}
16+
}
17+
18+
return result;
19+
}
20+
921
function decodeBody(body: { encoding: string; value: string }): string | ArrayBuffer {
1022
if (body.encoding === "utf8") return body.value;
1123
const buf = Buffer.from(body.value, "base64");
@@ -33,7 +45,7 @@ export async function proxyRequest(
3345
try {
3446
const res = await fetch(url, init);
3547
const bodyBytes = new Uint8Array(await res.arrayBuffer());
36-
const responseHeaders: [string, string][] = Array.from(res.headers.entries());
48+
const responseHeaders = filterResponseHeaders(res.headers);
3749

3850
const response: SerializedHttpResponse = {
3951
requestId: request.requestId,

0 commit comments

Comments
 (0)