From 39f7a38c20a1b7020c4a45db1778d0c3cef85f10 Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Thu, 18 Mar 2021 17:10:28 +0530 Subject: [PATCH] fix: clone reponse in put() (#3) --- in_memory_test.ts | 2 +- mod.ts | 5 ++--- redis_test.ts | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/in_memory_test.ts b/in_memory_test.ts index 9ada8f5..11bee30 100644 --- a/in_memory_test.ts +++ b/in_memory_test.ts @@ -21,7 +21,7 @@ Deno.test("[in memory] cache, retrieve, delete", async () => { originalResp.headers.get("server"), cachedResp.headers.get("server"), ); - assertEquals(await cachedResp.text(), "Hello World"); + assertEquals(await originalResp.text(), await cachedResp.text()); await cache.delete("https://deno.land"); diff --git a/mod.ts b/mod.ts index 9ede274..58de105 100644 --- a/mod.ts +++ b/mod.ts @@ -51,9 +51,8 @@ export class Cache { } async put(request: RequestInfo, response: Response): Promise { - const req = request instanceof Request - ? request.clone() - : new Request(request); + const req = request instanceof Request ? request : new Request(request); + response = response.clone(); const status = response.status; const headers = Object.fromEntries(response.headers.entries()); diff --git a/redis_test.ts b/redis_test.ts index 46383ff..3a53d7d 100644 --- a/redis_test.ts +++ b/redis_test.ts @@ -21,7 +21,7 @@ Deno.test("[redis] cache, retrieve, delete", async () => { originalResp.headers.get("server"), cachedResp.headers.get("server"), ); - assertEquals(await cachedResp.text(), "Hello World"); + assertEquals(await originalResp.text(), await cachedResp.text()); await cache.delete("https://deno.land");