@@ -1097,3 +1097,34 @@ describe("onAPIError", () => {
10971097 expect ( error ?. status ) . toBe ( "UNAUTHORIZED" ) ;
10981098 } ) ;
10991099} ) ;
1100+
1101+ describe ( "responseHeaders" , ( ) => {
1102+ it ( "exposes the live response headers accumulator inside the handler" , async ( ) => {
1103+ const endpoint = createEndpoint ( "/test" , { method : "GET" } , async ( ctx ) => {
1104+ ctx . setCookie ( "session" , "abc" ) ;
1105+ ctx . setHeader ( "x-custom" , "1" ) ;
1106+ const setCookies = ctx . responseHeaders . getSetCookie ( ) ;
1107+ const custom = ctx . responseHeaders . get ( "x-custom" ) ;
1108+ return { setCookies, custom } ;
1109+ } ) ;
1110+ const result = await endpoint ( ) ;
1111+ expect ( result . custom ) . toBe ( "1" ) ;
1112+ expect ( result . setCookies ) . toHaveLength ( 1 ) ;
1113+ expect ( result . setCookies [ 0 ] ) . toMatch ( / ^ s e s s i o n = a b c / ) ;
1114+ } ) ;
1115+
1116+ it ( "lets a later handler step observe what an earlier one wrote" , async ( ) => {
1117+ const endpoint = createEndpoint ( "/test" , { method : "GET" } , async ( ctx ) => {
1118+ ctx . setCookie ( "first" , "v1" ) ;
1119+ const alreadySet = ctx . responseHeaders
1120+ . getSetCookie ( )
1121+ . some ( ( c ) => c . startsWith ( "first=" ) ) ;
1122+ if ( ! alreadySet ) {
1123+ ctx . setCookie ( "first" , "v2" ) ;
1124+ }
1125+ return { count : ctx . responseHeaders . getSetCookie ( ) . length } ;
1126+ } ) ;
1127+ const result = await endpoint ( ) ;
1128+ expect ( result . count ) . toBe ( 1 ) ;
1129+ } ) ;
1130+ } ) ;
0 commit comments