File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,4 +5,18 @@ test.describe("api calls", () => {
55 const response = await fetch ( "http://localhost:3000/api/text-plain" ) ;
66 expect ( await response . text ( ) ) . toBe ( "test" ) ;
77 } ) ;
8+
9+ test ( "should include headers from both event and returned request" , async ( ) => {
10+ const okResp = await fetch ( "http://localhost:3000/api/header-merging?status=ok" ) ;
11+ expect ( okResp . headers . get ( "Set-Cookie" ) ) . toBeTruthy ( ) ;
12+ expect ( okResp . headers . get ( "x-event-header" ) ) . toBe ( "value" ) ;
13+ expect ( okResp . headers . get ( "x-return-header" ) ) . toBe ( "value" ) ;
14+ expect ( okResp . headers . get ( "x-shared-header" ) ) . toBe ( "event" ) ;
15+
16+ const redirectResp = await fetch ( "http://localhost:3000/api/header-merging?status=redirect" , { redirect : "manual" } ) ;
17+ expect ( redirectResp . headers . get ( "Set-Cookie" ) ) . toBeTruthy ( ) ;
18+ expect ( redirectResp . headers . get ( "x-event-header" ) ) . toBe ( "value" ) ;
19+ expect ( redirectResp . headers . get ( "x-return-header" ) ) . toBe ( "value" ) ;
20+ expect ( redirectResp . headers . get ( "x-shared-header" ) ) . toBe ( "event" ) ;
21+ } )
822} ) ;
Original file line number Diff line number Diff line change 1+ import { getRequestURL , setHeader , useSession } from "@solidjs/start/http" ;
2+
3+ export async function GET ( ) {
4+ const url = getRequestURL ( ) ;
5+
6+ const s = await useSession ( { password : "0" . repeat ( 32 ) } ) ;
7+ await s . update ( d => ( { count : ( d . count || 0 ) + 1 } ) )
8+
9+ setHeader ( "x-event-header" , "value" ) ;
10+ setHeader ( "x-shared-header" , "event" ) ;
11+
12+ if ( url . searchParams . get ( "status" ) === "redirect" ) {
13+ return new Response ( null , {
14+ status : 301 ,
15+ headers : {
16+ location : "http://::/abc" ,
17+ "x-return-header" : "value" ,
18+ "x-shared-header" : "return"
19+ }
20+ } )
21+ } else {
22+ return new Response ( null , {
23+ headers : {
24+ "x-return-header" : "value" ,
25+ "x-shared-header" : "return"
26+ }
27+ } )
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments