From c21fadf9bcc939dcf7d949cda86c974481b5f609 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Sun, 2 Jul 2023 23:24:15 -0400 Subject: set content-length 0 in some cases (#3503) --- test/js/web/fetch/fetch.test.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/js/web/fetch/fetch.test.ts') diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts index 4d529b231..6b87cc613 100644 --- a/test/js/web/fetch/fetch.test.ts +++ b/test/js/web/fetch/fetch.test.ts @@ -387,6 +387,25 @@ describe("fetch", () => { }).toThrow("fetch() request with GET/HEAD/OPTIONS method cannot have body."); }), ); + + it("content length is inferred", async () => { + startServer({ + fetch(req) { + return new Response(req.headers.get("content-length")); + }, + hostname: "localhost", + }); + + // POST with body + const url = `http://${server.hostname}:${server.port}`; + const response = await fetch(url, { method: "POST", body: "buntastic" }); + expect(response.status).toBe(200); + expect(await response.text()).toBe("9"); + + const response2 = await fetch(url, { method: "POST", body: "" }); + expect(response2.status).toBe(200); + expect(await response2.text()).toBe("0"); + }); }); it("simultaneous HTTPS fetch", async () => { -- cgit v1.2.3