Skip to content

Commit

Permalink
update comment to explain hack, make use of inpsect route in test, an…
Browse files Browse the repository at this point in the history
…d update changelog
  • Loading branch information
David Frank committed Jul 11, 2015
1 parent 5d15372 commit b64073c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
6 changes: 0 additions & 6 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 14 additions & 13 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
});
});

});

0 comments on commit b64073c

Please sign in to comment.