node-fetch
Advanced tools
Comparing version 1.4.0 to 1.4.1
@@ -8,4 +8,8 @@ | ||
## v1.4.0 (master) | ||
## v1.4.1 (master) | ||
- Fix: wrapping Request instance with FormData body again should preserve the body as-is | ||
## v1.4.0 | ||
- Enhance: Request and Response now have `clone` method (thx to @kirill-konshin for the initial PR) | ||
@@ -12,0 +16,0 @@ - Enhance: Request and Response now have proper string and buffer body support (thx to @kirill-konshin) |
@@ -209,2 +209,3 @@ /** | ||
// don't allow cloning a used body | ||
if (instance.bodyUsed) { | ||
@@ -214,3 +215,5 @@ throw new Error('cannot clone body after it is used'); | ||
if (bodyStream(body)) { | ||
// check that body is a stream and not form-data object | ||
// note: we can't clone the form-data object without having it as a dependency | ||
if (bodyStream(body) && typeof body.getBoundary !== 'function') { | ||
pass = new PassThrough(); | ||
@@ -217,0 +220,0 @@ body.pipe(pass); |
@@ -20,3 +20,1 @@ | ||
- There is currently no built-in caching, as server-side caching varies by use-cases. | ||
- Avoid using `Request` and `Response` constructors directly, as they are not spec-compliant yet (see open issues). |
{ | ||
"name": "node-fetch", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "A light-weight module that brings window.fetch to node.js and io.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -803,9 +803,9 @@ | ||
it('should allow cloning a json response, and log it as text response', function() { | ||
it('should allow cloning a json response and log it as text response', function() { | ||
url = base + '/json'; | ||
return fetch(url).then(function(res) { | ||
var r1 = res.clone(); | ||
return fetch.Promise.all([r1.text(), res.json()]).then(function(results) { | ||
expect(results[0]).to.equal('{"name":"value"}'); | ||
expect(results[1]).to.deep.equal({name: 'value'}); | ||
return fetch.Promise.all([res.json(), r1.text()]).then(function(results) { | ||
expect(results[0]).to.deep.equal({name: 'value'}); | ||
expect(results[1]).to.equal('{"name":"value"}'); | ||
}); | ||
@@ -815,2 +815,15 @@ }); | ||
it('should allow cloning a json response, and then log it as text response', function() { | ||
url = base + '/json'; | ||
return fetch(url).then(function(res) { | ||
var r1 = res.clone(); | ||
return res.json().then(function(result) { | ||
expect(result).to.deep.equal({name: 'value'}); | ||
return r1.text().then(function(result) { | ||
expect(result).to.equal('{"name":"value"}'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('should not allow cloning a response after its been used', function() { | ||
@@ -947,11 +960,19 @@ url = base + '/hello'; | ||
url = base + '/hello'; | ||
var form = new FormData(); | ||
form.append('a', '1'); | ||
var r1 = new Request(url, { | ||
method: 'POST' | ||
, follow: 1 | ||
, body: form | ||
}); | ||
var r2 = new Request(r1, { | ||
follow: 2 | ||
}) | ||
}); | ||
expect(r2.url).to.equal(url); | ||
expect(r2.method).to.equal('POST'); | ||
// note that we didn't clone the body | ||
expect(r2.body).to.equal(form); | ||
expect(r1.follow).to.equal(1); | ||
@@ -1015,3 +1036,5 @@ expect(r2.follow).to.equal(2); | ||
it('should support clone() method in Response constructor', function() { | ||
var res = new Response('a=1', { | ||
var body = resumer().queue('a=1').end(); | ||
body = body.pipe(new stream.PassThrough()); | ||
var res = new Response(body, { | ||
headers: { | ||
@@ -1030,2 +1053,4 @@ a: '1' | ||
expect(cl.ok).to.be.false; | ||
// clone body shouldn't be the same body | ||
expect(cl.body).to.not.equal(body); | ||
return cl.text().then(function(result) { | ||
@@ -1094,5 +1119,7 @@ expect(result).to.equal('a=1'); | ||
url = base; | ||
var body = resumer().queue('a=1').end(); | ||
body = body.pipe(new stream.PassThrough()); | ||
var agent = new http.Agent(); | ||
var req = new Request(url, { | ||
body: 'a=1' | ||
body: body | ||
, method: 'POST' | ||
@@ -1115,2 +1142,4 @@ , headers: { | ||
expect(cl.agent).to.equal(agent); | ||
// clone body shouldn't be the same body | ||
expect(cl.body).to.not.equal(body); | ||
return fetch.Promise.all([cl.text(), req.text()]).then(function(results) { | ||
@@ -1117,0 +1146,0 @@ expect(results[0]).to.equal('a=1'); |
66792
1883
92