|
1 | | -import { isNoTransform } from "./utils.ts"; |
2 | | -import { assert, describe, it } from "./_dev_deps.ts"; |
| 1 | +import { isNoTransform, reCalcContentLength } from "./utils.ts"; |
| 2 | +import { assert, describe, equalsResponse, it } from "./_dev_deps.ts"; |
3 | 3 |
|
4 | 4 | describe("isNoTransform", () => { |
5 | 5 | it("should return true", () => { |
@@ -28,3 +28,40 @@ describe("isNoTransform", () => { |
28 | 28 | }); |
29 | 29 | }); |
30 | 30 | }); |
| 31 | + |
| 32 | +describe("reCalcContentLength", () => { |
| 33 | + it("should have new content-length if the response has content-length header", async () => { |
| 34 | + const response = await reCalcContentLength( |
| 35 | + new Response("abc", { headers: { "content-length": "100000" } }), |
| 36 | + ); |
| 37 | + |
| 38 | + assert( |
| 39 | + equalsResponse( |
| 40 | + response, |
| 41 | + new Response("abc", { headers: { "content-length": "3" } }), |
| 42 | + true, |
| 43 | + ), |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + it("should return same response if the response has been read", async () => { |
| 48 | + const initResponse = new Response("abc", { |
| 49 | + headers: { "content-length": "100000" }, |
| 50 | + }); |
| 51 | + |
| 52 | + await initResponse.text(); |
| 53 | + |
| 54 | + assert(initResponse.bodyUsed); |
| 55 | + |
| 56 | + const response = await reCalcContentLength(initResponse); |
| 57 | + |
| 58 | + assert(initResponse === response); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should return same response if the response does not have content-length header", async () => { |
| 62 | + const initResponse = new Response("abc"); |
| 63 | + const response = await reCalcContentLength(initResponse); |
| 64 | + |
| 65 | + assert(initResponse === response); |
| 66 | + }); |
| 67 | +}); |
0 commit comments