@@ -88,7 +88,7 @@ describe('redirect', () => {
88
88
expect ( response . status ) . toBe ( 307 )
89
89
expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
90
90
expect (
91
- new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
91
+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
92
92
'redirected to the correct path' ,
93
93
) . toEqual ( '/other' )
94
94
expect ( origin . calls ) . toBe ( 0 )
@@ -111,12 +111,34 @@ describe('redirect', () => {
111
111
expect ( response . status ) . toBe ( 307 )
112
112
expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
113
113
expect (
114
- new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
114
+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
115
115
'redirected to the correct path' ,
116
116
) . toEqual ( '/other' )
117
117
expect ( response . headers . get ( 'x-header-from-redirect' ) , 'hello' ) . toBe ( 'hello' )
118
118
expect ( origin . calls ) . toBe ( 0 )
119
119
} )
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
+ } )
120
142
} )
121
143
122
144
describe ( 'rewrite' , ( ) => {
@@ -309,7 +331,7 @@ describe('should run middleware on data requests', () => {
309
331
expect ( response . status ) . toBe ( 307 )
310
332
expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
311
333
expect (
312
- new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
334
+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
313
335
'redirected to the correct path' ,
314
336
) . toEqual ( '/other' )
315
337
expect ( response . headers . get ( 'x-header-from-redirect' ) , 'hello' ) . toBe ( 'hello' )
@@ -333,7 +355,7 @@ describe('should run middleware on data requests', () => {
333
355
expect ( response . status ) . toBe ( 307 )
334
356
expect ( response . headers . get ( 'location' ) , 'added a location header' ) . toBeTypeOf ( 'string' )
335
357
expect (
336
- new URL ( response . headers . get ( 'location' ) as string ) . pathname ,
358
+ new URL ( response . headers . get ( 'location' ) ! ) . pathname ,
337
359
'redirected to the correct path' ,
338
360
) . toEqual ( '/other' )
339
361
expect ( response . headers . get ( 'x-header-from-redirect' ) , 'hello' ) . toBe ( 'hello' )
0 commit comments