From b64073c64cb82b58ed3c93d1327eb033f022f033 Mon Sep 17 00:00:00 2001 From: David Frank Date: Sat, 11 Jul 2015 19:38:26 +0800 Subject: [PATCH 1/2] update comment to explain hack, make use of inpsect route in test, and update changelog --- CHANGELOG.md | 8 ++++++-- index.js | 2 +- test/server.js | 6 ------ test/test.js | 27 ++++++++++++++------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37e6e3b..46cd053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,13 @@ Changelog # 1.x release -## v1.3.0 (master) +## v1.3.1 -- 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'); - }); - }); - }); From ebaf735cc20c0a674ca94a20af2bc82f10194c80 Mon Sep 17 00:00:00 2001 From: David Frank Date: Sat, 11 Jul 2015 19:39:16 +0800 Subject: [PATCH 2/2] mark release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46cd053..430d4e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ Changelog # 1.x release -## v1.3.1 +## v1.3.1 (master) - Enhance: allow custom host header to be set (server-side only feature, as it's a forbidden header on client-side)