diff options
Diffstat (limited to 'test/bun.js')
-rw-r--r-- | test/bun.js/fetch-gzip.test.ts | 3 | ||||
-rw-r--r-- | test/bun.js/fetch.test.js | 2 | ||||
-rw-r--r-- | test/bun.js/proxy.test.js | 60 | ||||
-rw-r--r-- | test/bun.js/serve.test.ts | 1 |
4 files changed, 61 insertions, 5 deletions
diff --git a/test/bun.js/fetch-gzip.test.ts b/test/bun.js/fetch-gzip.test.ts index 6dc8d2a7f..bdfc48f53 100644 --- a/test/bun.js/fetch-gzip.test.ts +++ b/test/bun.js/fetch-gzip.test.ts @@ -24,7 +24,6 @@ it("fetch() with a buffered gzip response works (one chunk)", async () => { const res = await fetch( `http://${server.hostname}:${server.port}`, - {}, { verbose: true }, ); gcTick(true); @@ -64,7 +63,6 @@ it("fetch() with a redirect that returns a buffered gzip response works (one chu const res = await fetch( `http://${server.hostname}:${server.port}/hey`, - {}, { verbose: true }, ); const arrayBuffer = await res.arrayBuffer(); @@ -100,7 +98,6 @@ it("fetch() with a protocol-relative redirect that returns a buffered gzip respo const res = await fetch( `http://${server.hostname}:${server.port}/hey`, - {}, { verbose: true }, ); expect(res.url).toBe(`http://${server.hostname}:${server.port}/redirect`); diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js index 5d0ca4854..28a7c109b 100644 --- a/test/bun.js/fetch.test.js +++ b/test/bun.js/fetch.test.js @@ -127,7 +127,7 @@ describe("fetch", () => { } it(name, async () => { gc(); - const response = await fetch(url, {}, { verbose: true }); + const response = await fetch(url, { verbose: true }); gc(); const text = await response.text(); gc(); diff --git a/test/bun.js/proxy.test.js b/test/bun.js/proxy.test.js new file mode 100644 index 000000000..32b21f7e8 --- /dev/null +++ b/test/bun.js/proxy.test.js @@ -0,0 +1,60 @@ +import { afterAll, beforeAll, describe, expect, it } from "bun:test"; +import { gc } from "./gc"; + +let proxy, server; + +// TODO: Proxy with TLS requests + +beforeAll(()=> { + proxy = Bun.serve({ + async fetch(request) { + // if is not an proxy connection just drop it + if (!request.headers.has("proxy-connection")) { + return new Response("Bad Request", { status: 400 }); + } + + // simple http proxy + if (request.url.startsWith("http://")) { + return await fetch(request.url, { method: request.method, body: await request.text() }); + } + + // no TLS support here + return new Response("Bad Request", { status: 400 }); + + }, + port: 54321, + }); + server = Bun.serve({ + async fetch(request) { + if (request.method === "POST"){ + const text = await request.text(); + return new Response(text,{ status: 200 }); + } + return new Response("Hello, World",{ status: 200 }); + }, + port: 54322, + }); +}); + +afterAll(() => { + server.stop(); + proxy.stop(); +}); + +describe("proxy", () => { + const requests = [ + [ new Request("http://localhost:54322"), "fetch() GET with non-TLS Proxy", "http://localhost:54321"], + [ new Request("http://localhost:54322", { method: "POST", body: "Hello, World" }), "fetch() POST with non-TLS Proxy", "http://localhost:54321"] + ]; + for (let [ request, name, proxy ] of requests) { + gc(); + it(name, async () => { + gc(); + const response = await fetch(request, { verbose: true, proxy }); + gc(); + const text = await response.text(); + gc(); + expect(text).toBe("Hello, World"); + }); + } +});
\ No newline at end of file diff --git a/test/bun.js/serve.test.ts b/test/bun.js/serve.test.ts index 1961f58ad..86c5585ce 100644 --- a/test/bun.js/serve.test.ts +++ b/test/bun.js/serve.test.ts @@ -905,7 +905,6 @@ describe("should support Content-Range with Bun.file()", () => { await getServer(async (server) => { const response = await fetch( `http://${server.hostname}:${server.port}/?start=${start}&end=${end}`, - {}, { verbose: true }, ); expect(await response.arrayBuffer()).toEqual( |