expose response and headers constructors

This commit is contained in:
Rhys Evans 2015-05-03 09:37:58 +01:00
parent 377bce655f
commit 5e4d9b1a60
3 changed files with 8 additions and 0 deletions

View File

@ -26,6 +26,7 @@ Hence `node-fetch`, minimal code for a `window.fetch` compatible API on node.js/
- Use native stream for body, on both request and response.
- Decode content encoding (gzip/deflate) properly, and convert string output (such as `res.text()` and `res.json()`) to utf-8 automatically.
- Useful extensions such as timeout, redirect limit, response size limit.
- Exposes `Response` and `Headers` constructors
# Difference from client-side fetch

View File

@ -190,3 +190,5 @@ Fetch.prototype.isRedirect = function(code) {
// expose Promise
Fetch.Promise = global.Promise;
Fetch.Response = Response;
Fetch.Headers = Headers;

View File

@ -59,6 +59,11 @@ describe('node-fetch', function() {
fetch.Promise = old;
});
it('should expose Headers and Response constructors', function() {
expect(fetch.Headers).to.equal(Headers);
expect(fetch.Response).to.equal(Response);
});
it('should reject with error if url is protocol relative', function() {
url = '//example.com/';
return expect(fetch(url)).to.eventually.be.rejectedWith(Error);