@@ -35,6 +35,12 @@ export default function(fn, opts={}) {
35
35
36
36
const proxy = httpProxy . createProxyServer ( { target } ) ;
37
37
38
+ proxy . on ( "proxyRes" , function ( proxyRes , req , res ) {
39
+ const existing = res . getHeader ( "Via" ) ;
40
+ const viaheader = `${ existing ? existing + ", " : "" } ${ req . httpVersion } ${ via } (${ name } /${ version } )` ;
41
+ res . setHeader ( "Via" , viaheader ) ;
42
+ } ) ;
43
+
38
44
return async function ( req , res , next ) {
39
45
try {
40
46
// hijack the root response and inject proxy information
@@ -51,20 +57,6 @@ export default function(fn, opts={}) {
51
57
if ( secret ) req . headers [ headerFields . token ] = signRequest ( name , secret ) ;
52
58
}
53
59
54
- // attach Via header on response
55
- // do this last in case there was an error
56
- if ( via ) {
57
- const writeHead = res . writeHead ;
58
- res . writeHead = function ( code , headers ) {
59
- const existing = res . getHeader ( "Via" ) ;
60
- const viaheader = `${ existing ? existing + ", " : "" } ${ req . httpVersion } ${ via } (${ name } /${ version } )` ;
61
- res . setHeader ( "Via" , viaheader ) ;
62
- if ( headers ) headers [ "Via" ] = viaheader ;
63
-
64
- return writeHead . apply ( res , arguments ) ;
65
- } ;
66
- }
67
-
68
60
proxy . web ( req , res ) ;
69
61
} catch ( e ) {
70
62
if ( next ) next ( e ) ;
0 commit comments