From 5e4d9b1a6078319a666b6a4fdbccb1913024d677 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Sun, 3 May 2015 09:37:58 +0100 Subject: [PATCH] expose response and headers constructors --- README.md | 1 + index.js | 2 ++ test/test.js | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 196de0c..45c282f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index aa490aa..c2451fd 100644 --- a/index.js +++ b/index.js @@ -190,3 +190,5 @@ Fetch.prototype.isRedirect = function(code) { // expose Promise Fetch.Promise = global.Promise; +Fetch.Response = Response; +Fetch.Headers = Headers; diff --git a/test/test.js b/test/test.js index 6a4168e..89cefbd 100644 --- a/test/test.js +++ b/test/test.js @@ -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);