File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -163,7 +163,8 @@ export const buildResponse = async ({
163163 method : request . method ,
164164 } )
165165 }
166- return addMiddlewareHeaders ( fetch ( proxyRequest ) , res )
166+
167+ return addMiddlewareHeaders ( fetch ( proxyRequest , { redirect : 'manual' } ) , res )
167168 } else if ( isDataReq ) {
168169 rewriteUrl . pathname = rewriteDataPath ( {
169170 dataUrl : originalPath ,
Original file line number Diff line number Diff line change @@ -153,6 +153,34 @@ describe('rewrite', () => {
153153 expect ( external . calls ) . toBe ( 1 )
154154 expect ( origin . calls ) . toBe ( 0 )
155155 } )
156+
157+ test < FixtureTestContext > ( 'rewriting to external URL that redirects should return said redirect' , async ( ctx ) => {
158+ await createFixture ( 'middleware' , ctx )
159+ await runPlugin ( ctx )
160+
161+ const external = await LocalServer . run ( async ( req , res ) => {
162+ res . writeHead ( 302 , {
163+ location : 'http://example.com/redirected' ,
164+ } )
165+ res . end ( )
166+ } )
167+ ctx . cleanup ?. push ( ( ) => external . stop ( ) )
168+
169+ const origin = new LocalServer ( )
170+ ctx . cleanup ?. push ( ( ) => origin . stop ( ) )
171+
172+ const response = await invokeEdgeFunction ( ctx , {
173+ functions : [ '___netlify-edge-handler-middleware' ] ,
174+ origin,
175+ url : `/test/rewrite-external?external-url=http://localhost:${ external . port } /some-path` ,
176+ redirect : 'manual' ,
177+ } )
178+
179+ expect ( await response . text ( ) ) . toBe ( '' )
180+
181+ expect ( response . status ) . toBe ( 302 )
182+ expect ( response . headers . get ( 'location' ) ) . toBe ( 'http://example.com/redirected' )
183+ } )
156184} )
157185
158186describe ( "aborts middleware execution when the matcher conditions don't match the request" , ( ) => {
You can’t perform that action at this time.
0 commit comments