Skip to content

Commit

Permalink
Return custom Content-Encodings, closes #312
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot committed Aug 11, 2022
1 parent 67d35f8 commit ae2349c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 0 additions & 1 deletion packages/http-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/http-server/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand Down

0 comments on commit ae2349c

Please sign in to comment.