From ae2349ca536e543a01e3dd866512f03381727b65 Mon Sep 17 00:00:00 2001 From: bcoll Date: Thu, 11 Aug 2022 13:03:47 +0100 Subject: [PATCH] Return custom `Content-Encoding`s, closes #312 --- packages/http-server/src/index.ts | 1 - packages/http-server/test/index.spec.ts | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/http-server/src/index.ts b/packages/http-server/src/index.ts index 98f20d382..4e26e7ba1 100644 --- a/packages/http-server/src/index.ts +++ b/packages/http-server/src/index.ts @@ -195,7 +195,6 @@ async function writeResponse( } else { // Unknown encoding, don't do any encoding at all log?.warn(`Unknown encoding \"${coding}\", sending plain response...`); - delete headers["content-encoding"]; encoders.length = 0; break; } diff --git a/packages/http-server/test/index.spec.ts b/packages/http-server/test/index.spec.ts index b964d4737..c6f5e630d 100644 --- a/packages/http-server/test/index.spec.ts +++ b/packages/http-server/test/index.spec.ts @@ -521,7 +521,7 @@ const autoEncodeMacro: Macro< http.get({ port }, async (res) => { t.is(res.headers["content-length"], undefined); t.is(res.headers["transfer-encoding"], "chunked"); - t.is(res.headers["content-encoding"], encodes ? encoding : undefined); + t.is(res.headers["content-encoding"], encoding); const compressed = await buffer(res); const decompressed = decompress(compressed); if (encodes) t.true(compressed.byteLength < decompressed.byteLength); @@ -542,6 +542,8 @@ test(autoEncodeMacro, "deflate, gZip", (buffer) => ); // Should skip all encoding with single unknown encoding test(autoEncodeMacro, "deflate, unknown, gzip", (buffer) => buffer, false); +// Should allow custom `Content-Encoding`s: https://github.com/cloudflare/miniflare/issues/312 +test(autoEncodeMacro, "custom", (buffer) => buffer, false); test("createRequestListener: skips encoding already encoded data", async (t) => { const encoded = new Uint8Array(zlib.gzipSync(Buffer.from(longText, "utf8"))); const mf = useMiniflareWithHandler(