diff options
author | 2023-09-04 21:37:47 -0300 | |
---|---|---|
committer | 2023-09-04 17:37:47 -0700 | |
commit | f1afd5833874e64822560a834c3484b2aa993656 (patch) | |
tree | b62431b12410dfae2120332c9eb727bafbe79bd2 /test | |
parent | 5f34c44ec6af175889e26aa5f42c817dd3de61c4 (diff) | |
download | bun-f1afd5833874e64822560a834c3484b2aa993656.tar.gz bun-f1afd5833874e64822560a834c3484b2aa993656.tar.zst bun-f1afd5833874e64822560a834c3484b2aa993656.zip |
fix zlib deflate on fetch (#4483)
* fix zlib deflate on fetch
* mention issue on test
* more tests
* oops
Diffstat (limited to 'test')
-rw-r--r-- | test/js/web/fetch/fetch.stream.test.ts | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/test/js/web/fetch/fetch.stream.test.ts b/test/js/web/fetch/fetch.stream.test.ts index dc082fd2f..49cc0dd6a 100644 --- a/test/js/web/fetch/fetch.stream.test.ts +++ b/test/js/web/fetch/fetch.stream.test.ts @@ -3,7 +3,7 @@ import { readFileSync } from "fs"; import { join } from "path"; import { describe, expect, it } from "bun:test"; import { gcTick } from "harness"; - +import zlib from "zlib"; const fixtures = { "fixture": readFileSync(join(import.meta.dir, "fixture.html")), "fixture.png": readFileSync(join(import.meta.dir, "fixture.png")), @@ -17,6 +17,40 @@ const smallText = Buffer.from("Hello".repeat(16)); const empty = Buffer.alloc(0); describe("fetch() with streaming", () => { + it("can deflate with and without headers #4478", async () => { + let server: Server | null = null; + try { + server = Bun.serve({ + port: 0, + fetch(req) { + if (req.url.endsWith("/with_headers")) { + const content = zlib.deflateSync(Buffer.from("Hello, World")); + return new Response(content, { + headers: { + "Content-Type": "text/plain", + "Content-Encoding": "deflate", + "Access-Control-Allow-Origin": "*", + }, + }); + } + const content = zlib.deflateRawSync(Buffer.from("Hello, World")); + return new Response(content, { + headers: { + "Content-Type": "text/plain", + "Content-Encoding": "deflate", + "Access-Control-Allow-Origin": "*", + }, + }); + }, + }); + const url = `http://${server.hostname}:${server.port}/`; + expect(await fetch(`${url}with_headers`).then(res => res.text())).toBe("Hello, World"); + expect(await fetch(url).then(res => res.text())).toBe("Hello, World"); + } finally { + server?.stop(); + } + }); + it("stream still works after response get out of scope", async () => { let server: Server | null = null; try { @@ -467,12 +501,13 @@ describe("fetch() with streaming", () => { } } - type CompressionType = "no" | "gzip" | "deflate" | "br"; + type CompressionType = "no" | "gzip" | "deflate" | "br" | "deflate_with_headers"; type TestType = { headers: Record<string, string>; compression: CompressionType; skip?: boolean }; const types: Array<TestType> = [ { headers: {}, compression: "no" }, { headers: { "Content-Encoding": "gzip" }, compression: "gzip" }, { headers: { "Content-Encoding": "deflate" }, compression: "deflate" }, + { headers: { "Content-Encoding": "deflate" }, compression: "deflate_with_headers" }, // { headers: { "Content-Encoding": "br" }, compression: "br", skip: true }, // not implemented yet ]; @@ -482,6 +517,8 @@ describe("fetch() with streaming", () => { return Bun.gzipSync(data); case "deflate": return Bun.deflateSync(data); + case "deflate_with_headers": + return zlib.deflateSync(data); default: return data; } |