diff --git a/lib/proxy.js b/lib/proxy.js index b2cd7d2..318b9c8 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -26,7 +26,11 @@ module.exports = function proxy(req, body, host) { return new Promise(function (resolve /* , reject */) { var uri = url.parse(host); var mod = mods[uri.protocol] || http; - var preq = mod.request({ + + var h = req.headers; + h['host'] = uri.host; + + var r = { hostname: uri.hostname, port: uri.port, method: req.method, @@ -35,11 +39,15 @@ module.exports = function proxy(req, body, host) { servername: uri.hostname, rejectUnauthorized: false - }, function (pres) { + }; + + debug('r', r); + + var preq = mod.request(r, function (pres) { resolve(pres); }); - - preq.setHeader('Host', uri.host); + + // preq.setHeader('Host', uri.host); debug('req', req.url, 'host', uri.host); diff --git a/test/proxy.js b/test/proxy.js index c994711..f68be5f 100644 --- a/test/proxy.js +++ b/test/proxy.js @@ -7,6 +7,7 @@ var subject = require('../lib/proxy'); var createServer = require('./helpers/server'); var assert = require('assert'); var http = require('http'); +var https = require('https'); describe('proxy', function () { var server, req; @@ -39,6 +40,19 @@ describe('proxy', function () { }); }); + it('overrides the host if one is set on the incoming request', function (done) { + server.once('request', function (preq) { + assert.equal(preq.headers.host, server.addr + ':' + server.port); + done(); + }); + + req.headers['host'] = 'A.N.OTHER' + + subject(req, [], server.host).catch(function (err) { + done(err); + }); + }); + it('proxies the request body', function (done) { var body = [ new Buffer('a'), @@ -75,4 +89,4 @@ describe('proxy', function () { }); }); -}); +}); \ No newline at end of file