diff --git a/CHANGELOG.md b/CHANGELOG.md index 37e6e3b..430d4e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,13 @@ Changelog # 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 diff --git a/index.js b/index.js index d5b0417..90bf132 100644 --- a/index.js +++ b/index.js @@ -79,7 +79,7 @@ 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’ + // http.request only support string as host header, this hack make custom host header possible if (options.headers.host) { options.headers.host = options.headers.host[0]; } diff --git a/test/server.js b/test/server.js index 55cb06d..1d17f5d 100644 --- a/test/server.js +++ b/test/server.js @@ -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(); - } - } diff --git a/test/test.js b/test/test.js index fdfdbbe..ab90a9f 100644 --- a/test/test.js +++ b/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() { url = base + '/redirect/301'; 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'); - }); - }); - });