diff --git a/lib/proxy.js b/lib/proxy.js index 1d876c0..e34a448 100755 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -26,6 +26,9 @@ function ReverseProxy(opts) { this.opts = opts = opts || {}; + opts.customHeaders = opts.customHeaders || {}; + this.opts = opts; + if (this.opts.httpProxy == undefined) { this.opts.httpProxy = {}; } @@ -103,12 +106,19 @@ function ReverseProxy(opts) { }); // - // Support NTLM auth + // Support NTLM auth and custom headers // - if (opts.ntlm) { + if (opts.ntlm || Object.keys(opts.customHeaders).length) { proxy.on('proxyRes', function (proxyRes) { - var key = 'www-authenticate'; - proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(','); + if (opts.ntlm) { + var key = 'www-authenticate'; + proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(','); + } + if (Object.keys(opts.customHeaders).length) { + Object.keys(opts.customHeaders).forEach(function (headerKey) { + proxyRes.headers[headerKey] = opts.customHeaders[headerKey]; + }) + } }); }