Skip to content

Commit cc32a79

Browse files
committed
stop cloning request body
1 parent 683d4c8 commit cc32a79

2 files changed

Lines changed: 1 addition & 13 deletions

File tree

src/helpers/cache_keys.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@ function getBodyCacheKeyJson(body: unknown): string | object | undefined {
5555
}
5656

5757
async function getRequestCacheKeyJson(request: Request) {
58-
const body = await request.arrayBuffer();
59-
6058
return {
6159
headers: getHeadersCacheKeyJson(Array.from(request.headers.entries())),
6260
method: request.method,
6361
redirect: request.redirect,
6462
referrer: request.referrer,
6563
url: request.url,
66-
body: getBodyCacheKeyJson(body),
64+
body: 'request_body' as undefined | string | object,
6765
// Confirmed that this property exists, but it's not in the types
6866
follow: (request as any).follow, // eslint-disable-line @typescript-eslint/no-unsafe-assignment
6967
// Confirmed that this property exists, but it's not in the types

src/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,12 @@ async function getResponse(
3838
resource: FetchResource,
3939
init: FetchInit,
4040
) {
41-
const originalResource = resource;
42-
4341
if (typeof resource !== 'string' && !(resource instanceof Request)) {
4442
throw new TypeError(
4543
'The first argument to fetch must be either a string or a fetch Request instance',
4644
);
4745
}
4846

49-
if (originalResource instanceof Request) {
50-
resource = originalResource.clone()
51-
}
52-
5347
const cacheKey = await fetchCustomization.calculateCacheKey(resource, init);
5448
const ejectSelfFromCache = async () => fetchCustomization.cache.remove(cacheKey);
5549

@@ -79,10 +73,6 @@ async function getResponse(
7973
true,
8074
);
8175
}
82-
83-
if (originalResource instanceof Request) {
84-
resource = originalResource.clone()
85-
}
8676

8777
const fetchResponse = await fetch(resource, init);
8878
const serializedMeta = NFCResponse.serializeMetaFromNodeFetchResponse(fetchResponse);

0 commit comments

Comments
 (0)