File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -18,5 +18,28 @@ test.describe("api calls", () => {
1818 expect ( redirectResp . headers . get ( "x-event-header" ) ) . toBe ( "value" ) ;
1919 expect ( redirectResp . headers . get ( "x-return-header" ) ) . toBe ( "value" ) ;
2020 expect ( redirectResp . headers . get ( "x-shared-header" ) ) . toBe ( "event" ) ;
21- } )
21+ } ) ;
22+
23+ test ( "should preserve multiple Set-Cookie headers on redirect (RFC 6265)" , async ( ) => {
24+
25+ const response = await fetch ( "http://localhost:3000/api/multi-set-cookie-redirect" , {
26+ redirect : "manual"
27+ } ) ;
28+
29+ expect ( response . status ) . toBe ( 302 ) ;
30+
31+ // Use getSetCookie() to retrieve all Set-Cookie headers as an array
32+ const cookies = response . headers . getSetCookie ( ) ;
33+
34+ // We expect 3 cookies:
35+ // 1. session=abc123 (from response headers)
36+ // 2. csrf=xyz789 (from response headers)
37+ // 3. event_cookie=from_event (from event.response headers via setHeader)
38+ expect ( cookies . length ) . toBe ( 3 ) ;
39+
40+ const cookieValues = cookies . join ( "; " ) ;
41+ expect ( cookieValues ) . toContain ( "session=abc123" ) ;
42+ expect ( cookieValues ) . toContain ( "csrf=xyz789" ) ;
43+ expect ( cookieValues ) . toContain ( "event_cookie=from_event" ) ;
44+ } ) ;
2245} ) ;
Original file line number Diff line number Diff line change 1+ import { setHeader } from "@solidjs/start/http" ;
2+
3+ export async function GET ( ) {
4+ // Set a cookie via the event headers (this tests merging event headers)
5+ setHeader ( "Set-Cookie" , "event_cookie=from_event; Path=/" ) ;
6+
7+ // This tests cloning redirect responses with multiple cookies
8+ const headers = new Headers ( ) ;
9+ headers . append ( "Location" , "http://localhost:3000/" ) ;
10+ headers . append ( "Set-Cookie" , "session=abc123; Path=/; HttpOnly" ) ;
11+ headers . append ( "Set-Cookie" , "csrf=xyz789; Path=/" ) ;
12+
13+ return new Response ( null , {
14+ status : 302 ,
15+ headers
16+ } ) ;
17+ }
You can’t perform that action at this time.
0 commit comments