Merge pull request #28 from matthew-andrews/custom-host
Allow a custom host to be set
This commit is contained in:
commit
5d153728f9
5
index.js
5
index.js
|
@ -79,6 +79,11 @@ function Fetch(url, opts) {
|
|||
|
||||
options.headers = headers.raw();
|
||||
|
||||
// HACK: headers.host must be a string, cannot be an array otherwise get error ‘undefined is not a function’
|
||||
if (options.headers.host) {
|
||||
options.headers.host = options.headers.host[0];
|
||||
}
|
||||
|
||||
// send request
|
||||
var req = send(options);
|
||||
var reqTimeout;
|
||||
|
|
|
@ -244,4 +244,10 @@ TestServer.prototype.router = function(req, res) {
|
|||
});
|
||||
}
|
||||
|
||||
if (p === '/host') {
|
||||
res.statusCode = 200;
|
||||
res.setHeader('Fetch-Sent-Host', req.headers.host);
|
||||
res.end();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
14
test/test.js
14
test/test.js
|
@ -751,4 +751,18 @@ describe('node-fetch', function() {
|
|||
expect(res.ok).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow setting of custom host', function() {
|
||||
url = base + '/host';
|
||||
opts = {
|
||||
method: 'HEAD',
|
||||
headers: {
|
||||
host: 'bitinn.net'
|
||||
}
|
||||
};
|
||||
return fetch(url, opts).then(function(res) {
|
||||
expect(res.headers.get('fetch-sent-host')).to.equal('bitinn.net');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue