commit
1c67d40567
|
@ -5,9 +5,13 @@ Changelog
|
||||||
|
|
||||||
# 1.x release
|
# 1.x release
|
||||||
|
|
||||||
## v1.3.0 (master)
|
## v1.3.1 (master)
|
||||||
|
|
||||||
- Enhance: now fetch.Request is exposed as well.
|
- Enhance: allow custom host header to be set (server-side only feature, as it's a forbidden header on client-side)
|
||||||
|
|
||||||
|
## v1.3.0
|
||||||
|
|
||||||
|
- Enhance: now fetch.Request is exposed as well
|
||||||
|
|
||||||
## v1.2.1
|
## v1.2.1
|
||||||
|
|
||||||
|
|
2
index.js
2
index.js
|
@ -79,7 +79,7 @@ function Fetch(url, opts) {
|
||||||
|
|
||||||
options.headers = headers.raw();
|
options.headers = headers.raw();
|
||||||
|
|
||||||
// HACK: headers.host must be a string, cannot be an array otherwise get error ‘undefined is not a function’
|
// http.request only support string as host header, this hack make custom host header possible
|
||||||
if (options.headers.host) {
|
if (options.headers.host) {
|
||||||
options.headers.host = options.headers.host[0];
|
options.headers.host = options.headers.host[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,10 +244,4 @@ TestServer.prototype.router = function(req, res) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p === '/host') {
|
|
||||||
res.statusCode = 200;
|
|
||||||
res.setHeader('Fetch-Sent-Host', req.headers.host);
|
|
||||||
res.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
27
test/test.js
27
test/test.js
|
@ -161,6 +161,20 @@ describe('node-fetch', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should accept custom host header', function() {
|
||||||
|
url = base + '/inspect';
|
||||||
|
opts = {
|
||||||
|
headers: {
|
||||||
|
host: 'example.com'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return fetch(url, opts).then(function(res) {
|
||||||
|
return res.json();
|
||||||
|
}).then(function(res) {
|
||||||
|
expect(res.headers['host']).to.equal('example.com');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should follow redirect code 301', function() {
|
it('should follow redirect code 301', function() {
|
||||||
url = base + '/redirect/301';
|
url = base + '/redirect/301';
|
||||||
return fetch(url).then(function(res) {
|
return fetch(url).then(function(res) {
|
||||||
|
@ -752,17 +766,4 @@ describe('node-fetch', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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