Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
Add option retainOriginalHost
Browse files Browse the repository at this point in the history
  • Loading branch information
edorivai committed Oct 24, 2017
1 parent c745750 commit ccfa9e2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = function(options) {
};

// set "Host" header to options.host (without protocol prefix), strip trailing slash
if (options.host)
if (options.host && options.retainOriginalHost !== true)
opt.headers.host = options.host
.slice(options.host.indexOf('://') + 3)
.replace(/\/$/, '');
Expand Down
24 changes: 24 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ describe('koa-proxy', function() {
ctx.status = 200;
return;
}
if (ctx.path === '/retain-original-host') {
var headers = ctx.request.header;
ctx.body = headers;
ctx.status = 200;
return;
}
if (ctx.querystring) {
// To test query string
ctx.body = ctx.querystring;
Expand Down Expand Up @@ -139,6 +145,24 @@ describe('koa-proxy', function() {
});
});

it('should have option retainOriginalHost', function(done) {
var app = new Koa();
app.use(proxy({
host: 'http://localhost:1234',
retainOriginalHost: true
}));
var server = http.createServer(app.callback());
request(server)
.get('/retain-original-host')
.set('Host', 'localhost') // manually set host, since supertest randomizes the port
.expect(200)
.end(function(err, res) {
if (err) return done(err);
res.body.host.should.equal('localhost');
done();
});
});

it("should have option host and map", function(done) {
var app = new Koa();
app.use(proxy({
Expand Down

0 comments on commit ccfa9e2

Please sign in to comment.