Skip to content

Commit 7114571

Browse files
authoredOct 28, 2020
Merge pull request #515 from holidaycheck/set-host-header-instead-of-adapting-url
Set host header instead of host in url
2 parents 8b1a1d8 + de056d2 commit 7114571

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed
 

‎lib/agent.js

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ methods.forEach(function(method) {
5454
req.ca(this._ca);
5555
req.cert(this._cert);
5656
req.key(this._key);
57+
if (this._host) {
58+
req.set('host', this._host);
59+
}
5760

5861
req.on('response', this._saveCookies.bind(this));
5962
req.on('redirect', this._saveCookies.bind(this));

‎lib/test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ module.exports = Test;
2727
* @api public
2828
*/
2929

30-
function Test(app, method, path, host) {
30+
function Test(app, method, path) {
3131
Request.call(this, method.toUpperCase(), path);
3232
this.redirects(0);
3333
this.buffer();
3434
this.app = app;
3535
this._asserts = [];
3636
this.url = typeof app === 'string'
3737
? app + path
38-
: this.serverAddress(app, path, host);
38+
: this.serverAddress(app, path);
3939
}
4040

4141
/**
@@ -53,15 +53,15 @@ Object.setPrototypeOf(Test.prototype, Request.prototype);
5353
* @api private
5454
*/
5555

56-
Test.prototype.serverAddress = function(app, path, host) {
56+
Test.prototype.serverAddress = function(app, path) {
5757
var addr = app.address();
5858
var port;
5959
var protocol;
6060

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

6767
/**

‎test/supertest.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,15 @@ describe('agent.host(host)', function () {
880880
const agent = request.agent(app);
881881

882882
app.get('/', function (req, res) {
883-
res.send();
883+
res.send({ hostname: req.hostname });
884884
});
885885

886886
agent
887887
.host('something.test')
888888
.get('/')
889889
.end(function (err, res) {
890-
err.hostname.should.equal('something.test');
890+
if (err) return done(err);
891+
res.body.hostname.should.equal('something.test');
891892
done();
892893
});
893894
});

0 commit comments

Comments
 (0)