@@ -18,6 +18,7 @@ async function run () {
1818
1919 origin . post ( '/this-has-data' , async ( request , reply ) => {
2020 if ( request . body . hello === 'world' ) {
21+ reply . header ( 'location' , '/something' )
2122 return { something : 'posted' }
2223 }
2324 throw new Error ( 'kaboom' )
@@ -184,7 +185,7 @@ async function run () {
184185 t . match ( headers , { 'x-test' : 'test' } )
185186 } )
186187
187- test ( 'keepPrefix true ' , async ( t ) => {
188+ test ( 'rewritePrefix ' , async ( t ) => {
188189 const proxyServer = Fastify ( )
189190
190191 proxyServer . register ( proxy , {
@@ -202,6 +203,27 @@ async function run () {
202203 const firstProxyPrefix = await got ( `http://localhost:${ proxyServer . server . address ( ) . port } /api/a` )
203204 t . equal ( firstProxyPrefix . body , 'this is /api2/a' )
204205 } )
206+
207+ test ( 'rewrite location headers' , async ( t ) => {
208+ const proxyServer = Fastify ( )
209+
210+ proxyServer . register ( proxy , {
211+ upstream : `http://localhost:${ origin . server . address ( ) . port } ` ,
212+ prefix : '/api'
213+ } )
214+
215+ await proxyServer . listen ( 0 )
216+
217+ t . tearDown ( ( ) => {
218+ proxyServer . close ( )
219+ } )
220+
221+ const { headers : { location } } = await got ( `http://localhost:${ proxyServer . server . address ( ) . port } /api/this-has-data` , {
222+ body : { hello : 'world' } ,
223+ json : true
224+ } )
225+ t . equal ( location , '/api/something' )
226+ } )
205227}
206228
207229run ( )
0 commit comments