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) {
200200 fastify . addContentTypeParser ( '*' , bodyParser )
201201 }
202202
203- function rewriteHeaders ( headers ) {
203+ function rewriteHeaders ( headers , req ) {
204204 const location = headers . location
205205 if ( location && ! isExternalUrl ( location ) ) {
206206 headers . location = location . replace ( rewritePrefix , fastify . prefix )
207207 }
208208 if ( oldRewriteHeaders ) {
209- headers = oldRewriteHeaders ( headers )
209+ headers = oldRewriteHeaders ( headers , req )
210210 }
211211 return headers
212212 }
Original file line number Diff line number Diff line change @@ -387,7 +387,10 @@ async function run () {
387387 upstream : `http://localhost:${ origin . server . address ( ) . port } ` ,
388388 prefix : '/api' ,
389389 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 )
391394 }
392395 } )
393396
@@ -397,10 +400,13 @@ async function run () {
397400 proxyServer . close ( )
398401 } )
399402
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' } )
404410 } )
405411
406412 test ( 'rewritePrefix' , async t => {
You can’t perform that action at this time.
0 commit comments