File tree 2 files changed +30
-1
lines changed
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 ({
163
163
method : request . method ,
164
164
} )
165
165
}
166
- return addMiddlewareHeaders ( fetch ( proxyRequest ) , res )
166
+
167
+ return addMiddlewareHeaders ( fetch ( proxyRequest , { redirect : 'manual' } ) , res )
167
168
} else if ( isDataReq ) {
168
169
rewriteUrl . pathname = rewriteDataPath ( {
169
170
dataUrl : originalPath ,
Original file line number Diff line number Diff line change @@ -153,6 +153,34 @@ describe('rewrite', () => {
153
153
expect ( external . calls ) . toBe ( 1 )
154
154
expect ( origin . calls ) . toBe ( 0 )
155
155
} )
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
+ } )
156
184
} )
157
185
158
186
describe ( "aborts middleware execution when the matcher conditions don't match the request" , ( ) => {
You can’t perform that action at this time.
0 commit comments