forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow disabling keep-alive (oven-sh#14569)
Co-authored-by: Ciro Spaciari <[email protected]>
- Loading branch information
1 parent
d2fe1ce
commit 5fc5335
Showing
2 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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!"); | ||
} | ||
}); |