Skip to content

Commit 1753858

Browse files
authored
Merge pull request #525 from samualtnorman/main
preserve headers in `query()`'s `handleResponse()`
2 parents 30f0866 + 0a2f556 commit 1753858

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

.changeset/rude-camels-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
preserve headers in `query()`'s `handleResponse()`

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)