@@ -193,4 +193,96 @@ describe('Mount', () => {
193193 message : 'hello world'
194194 } )
195195 } )
196+
197+ // https://github.com/elysiajs/elysia/issues/1618
198+ it ( 'preserve cookie header in mounted handler' , async ( ) => {
199+ const app = new Elysia ( ) . mount ( '/auth' , ( request ) => {
200+ return Response . json ( {
201+ cookie : request . headers . get ( 'cookie' )
202+ } )
203+ } )
204+
205+ const response = await app
206+ . handle (
207+ new Request ( 'http://localhost/auth/session' , {
208+ headers : {
209+ Cookie : 'session_token=abc123'
210+ }
211+ } )
212+ )
213+ . then ( ( x ) => x . json ( ) )
214+
215+ expect ( response ) . toEqual ( {
216+ cookie : 'session_token=abc123'
217+ } )
218+ } )
219+
220+ // https://github.com/elysiajs/elysia/issues/1618
221+ it ( 'preserve cookie header in mounted handler with prefix option' , async ( ) => {
222+ const app = new Elysia ( { prefix : '/auth' } ) . mount ( ( request ) => {
223+ return Response . json ( {
224+ cookie : request . headers . get ( 'cookie' )
225+ } )
226+ } )
227+
228+ const response = await app
229+ . handle (
230+ new Request ( 'http://localhost/auth/session' , {
231+ headers : {
232+ Cookie : 'session_token=abc123'
233+ }
234+ } )
235+ )
236+ . then ( ( x ) => x . json ( ) )
237+
238+ expect ( response ) . toEqual ( {
239+ cookie : 'session_token=abc123'
240+ } )
241+ } )
242+
243+ // https://github.com/elysiajs/elysia/issues/1618
244+ it ( 'preserve cookie header in mounted handler with aot: false' , async ( ) => {
245+ const app = new Elysia ( { aot : false } ) . mount ( '/auth' , ( request ) => {
246+ return Response . json ( {
247+ cookie : request . headers . get ( 'cookie' )
248+ } )
249+ } )
250+
251+ const response = await app
252+ . handle (
253+ new Request ( 'http://localhost/auth/session' , {
254+ headers : {
255+ Cookie : 'session_token=abc123'
256+ }
257+ } )
258+ )
259+ . then ( ( x ) => x . json ( ) )
260+
261+ expect ( response ) . toEqual ( {
262+ cookie : 'session_token=abc123'
263+ } )
264+ } )
265+
266+ // https://github.com/elysiajs/elysia/issues/1618
267+ it ( 'preserve multiple cookies in mounted handler' , async ( ) => {
268+ const app = new Elysia ( ) . mount ( '/auth' , ( request ) => {
269+ return Response . json ( {
270+ cookie : request . headers . get ( 'cookie' )
271+ } )
272+ } )
273+
274+ const response = await app
275+ . handle (
276+ new Request ( 'http://localhost/auth/session' , {
277+ headers : {
278+ Cookie : 'session_token=abc123; csrf_token=xyz789'
279+ }
280+ } )
281+ )
282+ . then ( ( x ) => x . json ( ) )
283+
284+ expect ( response ) . toEqual ( {
285+ cookie : 'session_token=abc123; csrf_token=xyz789'
286+ } )
287+ } )
196288} )
0 commit comments