Files
bun.sh/test/js/web/fetch/fetch-keepalive.test.ts
Jarred Sumner 5fc53353fb Allow disabling keep-alive (#14569)
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2024-10-14 16:58:42 -07:00

37 lines
855 B
TypeScript

import { test, expect } from "bun:test";
test("keepalive", async () => {
using server = Bun.serve({
port: 0,
async fetch(req) {
return new Response(JSON.stringify(req.headers.toJSON()));
},
});
{
const res = await fetch(`http://localhost:${server.port}`, {
keepalive: false,
});
const headers = await res.json();
expect(headers.connection).toBeUndefined();
}
{
const res = await fetch(`http://localhost:${server.port}`, {
keepalive: true,
});
const headers = await res.json();
expect(headers.connection).toBe("keep-alive");
}
{
const res = await fetch(`http://localhost:${server.port}`, {
keepalive: false,
headers: {
"Connection": "HELLO!",
},
});
const headers = await res.json();
expect(headers.connection).toBe("HELLO!");
}
});