Merge pull request #28 from matthew-andrews/custom-host

Allow a custom host to be set
This commit is contained in:
David Frank 2015-07-11 19:25:23 +08:00
commit 5d153728f9
3 changed files with 25 additions and 0 deletions

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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');
});
});
});