Skip to content

Commit 8acdc86

Browse files
committed
preserve headers in query()'s handleResponse()
1 parent c05ce35 commit 8acdc86

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/data/query.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ export function query<T extends (...args: any) => any>(fn: T, name: string): Cac
177177
function handleResponse(error: boolean) {
178178
return async (v: any | Response) => {
179179
if (v instanceof Response) {
180+
const e = getRequestEvent();
181+
182+
if (e) {
183+
for (const [ key, value ] of v.headers) {
184+
if (key == "set-cookie")
185+
e.response.headers.append("set-cookie", value);
186+
else
187+
e.response.headers.set(key, value);
188+
}
189+
}
190+
180191
const url = v.headers.get(LocationHeader);
181192

182193
if (url !== null) {
@@ -186,10 +197,7 @@ export function query<T extends (...args: any) => any>(fn: T, name: string): Cac
186197
navigate(url, { replace: true });
187198
});
188199
else if (!isServer) window.location.href = url;
189-
else if (isServer) {
190-
const e = getRequestEvent();
191-
if (e) e.response = { status: 302, headers: new Headers({ Location: url }) };
192-
}
200+
else if (e) e.response.status = 302;
193201

194202
return;
195203
}

0 commit comments

Comments
 (0)