@@ -88,7 +88,7 @@ describe('redirect', () => {
8888 expect ( response . status ) . toBe ( 307 )
8989 expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
9090 expect (
91- new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
91+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
9292 'redirected to the correct path' ,
9393 ) . toEqual ( '/other' )
9494 expect ( origin . calls ) . toBe ( 0 )
@@ -111,12 +111,34 @@ describe('redirect', () => {
111111 expect ( response . status ) . toBe ( 307 )
112112 expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
113113 expect (
114- new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
114+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
115115 'redirected to the correct path' ,
116116 ) . toEqual ( '/other' )
117117 expect ( response . headers . get ( 'x-header-from-redirect' ) , 'hello' ) . toBe ( 'hello' )
118118 expect ( origin . calls ) . toBe ( 0 )
119119 } )
120+
121+ test < FixtureTestContext > ( 'should ignore x-middleware-rewrite when redirecting' , async ( ctx ) => {
122+ await createFixture ( 'middleware' , ctx )
123+ await runPlugin ( ctx )
124+
125+ const origin = new LocalServer ( )
126+ const response = await invokeEdgeFunction ( ctx , {
127+ functions : [ '___netlify-edge-handler-middleware' ] ,
128+ origin,
129+ redirect : 'manual' ,
130+ url : '/test/rewrite-and-redirect' ,
131+ } )
132+
133+ ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
134+
135+ expect ( response . status ) . toBe ( 302 )
136+ expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
137+ expect (
138+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
139+ 'redirected to the correct path' ,
140+ ) . toEqual ( '/other' )
141+ } )
120142} )
121143
122144describe ( 'rewrite' , ( ) => {
@@ -309,7 +331,7 @@ describe('should run middleware on data requests', () => {
309331 expect ( response . status ) . toBe ( 307 )
310332 expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
311333 expect (
312- new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
334+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
313335 'redirected to the correct path' ,
314336 ) . toEqual ( '/other' )
315337 expect ( response . headers . get ( 'x-header-from-redirect' ) , 'hello' ) . toBe ( 'hello' )
@@ -333,7 +355,7 @@ describe('should run middleware on data requests', () => {
333355 expect ( response . status ) . toBe ( 307 )
334356 expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
335357 expect (
336- new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
358+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
337359 'redirected to the correct path' ,
338360 ) . toEqual ( '/other' )
339361 expect ( response . headers . get ( 'x-header-from-redirect' ) , 'hello' ) . toBe ( 'hello' )
0 commit comments