Skip to content

Commit

Permalink
Merge pull request #515 from holidaycheck/set-host-header-instead-of-…
Browse files Browse the repository at this point in the history
…adapting-url

Set host header instead of host in url
  • Loading branch information
niftylettuce committed Oct 28, 2020
2 parents 8b1a1d8 + de056d2 commit 7114571
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/agent.js
Expand Up @@ -54,6 +54,9 @@ methods.forEach(function(method) {
req.ca(this._ca);
req.cert(this._cert);
req.key(this._key);
if (this._host) {
req.set('host', this._host);
}

req.on('response', this._saveCookies.bind(this));
req.on('redirect', this._saveCookies.bind(this));
Expand Down
8 changes: 4 additions & 4 deletions lib/test.js
Expand Up @@ -27,15 +27,15 @@ module.exports = Test;
* @api public
*/

function Test(app, method, path, host) {
function Test(app, method, path) {
Request.call(this, method.toUpperCase(), path);
this.redirects(0);
this.buffer();
this.app = app;
this._asserts = [];
this.url = typeof app === 'string'
? app + path
: this.serverAddress(app, path, host);
: this.serverAddress(app, path);
}

/**
Expand All @@ -53,15 +53,15 @@ Object.setPrototypeOf(Test.prototype, Request.prototype);
* @api private
*/

Test.prototype.serverAddress = function(app, path, host) {
Test.prototype.serverAddress = function(app, path) {
var addr = app.address();
var port;
var protocol;

if (!addr) this._server = app.listen(0);
port = app.address().port;
protocol = app instanceof https.Server ? 'https' : 'http';
return protocol + '://' + (host || '127.0.0.1') + ':' + port + path;
return protocol + '://127.0.0.1:' + port + path;
};

/**
Expand Down
5 changes: 3 additions & 2 deletions test/supertest.js
Expand Up @@ -880,14 +880,15 @@ describe('agent.host(host)', function () {
const agent = request.agent(app);

app.get('/', function (req, res) {
res.send();
res.send({ hostname: req.hostname });
});

agent
.host('something.test')
.get('/')
.end(function (err, res) {
err.hostname.should.equal('something.test');
if (err) return done(err);
res.body.hostname.should.equal('something.test');
done();
});
});
Expand Down

0 comments on commit 7114571

Please sign in to comment.