Skip to content

Commit

Permalink
fix: clone reponse in put() (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
satyarohith authored Mar 18, 2021
1 parent 107c962 commit 39f7a38
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion in_memory_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
5 changes: 2 additions & 3 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ export class Cache {
}

async put(request: RequestInfo, response: Response): Promise<void> {
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());
Expand Down
2 changes: 1 addition & 1 deletion redis_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 39f7a38

Please sign in to comment.