Skip to content

Commit 615c50f

Browse files
committed
attemp to fix 'TypeError: Can't modify immutable headers'
1 parent 0d02874 commit 615c50f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/functions.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
* It will delete the header from response if the value is falsely
1515
*/
1616
export function setHeaders(res: SWRResponse, headers: SWRHeader) {
17-
let nextRes = res.clone();
17+
let nextRes = new Response(res.clone().body, {
18+
status: res.status,
19+
headers: res.headers,
20+
});
1821

1922
for (let headersKey in headers) {
2023
let headerValue = headers[headersKey];
@@ -100,7 +103,10 @@ export function clientCacheControl(cacheControl: SWRCacheControl) {
100103
return value.join(', ');
101104
}
102105

103-
export function edgeCacheControl(cacheControl: SWRCacheControl, type: 'error' | 'success'): string {
106+
export function edgeCacheControl(
107+
cacheControl: SWRCacheControl,
108+
type: 'error' | 'success',
109+
): string {
104110
let value: string[] = [];
105111

106112
if (cacheControl['public'] !== undefined) {
@@ -110,7 +116,10 @@ export function edgeCacheControl(cacheControl: SWRCacheControl, type: 'error' |
110116
}
111117

112118
let maxAge = Number(cacheControl['s-maxage'] || cacheControl['max-age'] || 0);
113-
let staleUntil = cacheControl[type === 'success' ? 'stale-while-revalidate' : 'stale-if-error'];
119+
let staleUntil =
120+
cacheControl[
121+
type === 'success' ? 'stale-while-revalidate' : 'stale-if-error'
122+
];
114123

115124
// when null stale forever
116125
// when undefined means content should not stale

0 commit comments

Comments
 (0)