File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -200,13 +200,13 @@ async function httpProxy (fastify, opts) {
200
200
fastify . addContentTypeParser ( '*' , bodyParser )
201
201
}
202
202
203
- function rewriteHeaders ( headers ) {
203
+ function rewriteHeaders ( headers , req ) {
204
204
const location = headers . location
205
205
if ( location && ! isExternalUrl ( location ) ) {
206
206
headers . location = location . replace ( rewritePrefix , fastify . prefix )
207
207
}
208
208
if ( oldRewriteHeaders ) {
209
- headers = oldRewriteHeaders ( headers )
209
+ headers = oldRewriteHeaders ( headers , req )
210
210
}
211
211
return headers
212
212
}
Original file line number Diff line number Diff line change @@ -387,7 +387,10 @@ async function run () {
387
387
upstream : `http://localhost:${ origin . server . address ( ) . port } ` ,
388
388
prefix : '/api' ,
389
389
replyOptions : {
390
- rewriteHeaders : headers => Object . assign ( { 'x-test' : 'test' } , headers )
390
+ rewriteHeaders : ( headers , req ) => Object . assign ( {
391
+ 'x-test' : 'test' ,
392
+ 'x-req' : req . headers [ 'x-req' ]
393
+ } , headers )
391
394
}
392
395
} )
393
396
@@ -397,10 +400,13 @@ async function run () {
397
400
proxyServer . close ( )
398
401
} )
399
402
400
- const { headers } = await got (
401
- `http://localhost:${ proxyServer . server . address ( ) . port } /api`
402
- )
403
- t . match ( headers , { 'x-test' : 'test' } )
403
+ const { headers } = await got ( {
404
+ url : `http://localhost:${ proxyServer . server . address ( ) . port } /api` ,
405
+ headers : {
406
+ 'x-req' : 'from-header'
407
+ }
408
+ } )
409
+ t . match ( headers , { 'x-test' : 'test' , 'x-req' : 'from-header' } )
404
410
} )
405
411
406
412
test ( 'rewritePrefix' , async t => {
You can’t perform that action at this time.
0 commit comments