Socket
Socket
Sign inDemoInstall

node-fetch

Package Overview
Dependencies
4
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.0 to 1.6.1

18

CHANGELOG.md

@@ -8,5 +8,11 @@

## v1.6.0 (master)
## v1.6.1 (master)
- Enhance: added res.buffer() api for convenience, it returns body as a Node.js buffer
- Fix: if `res.body` is a non-stream non-formdata object, we will call `body.toString` and send it as a string
- Fix: `counter` value is incorrectly set to `follow` value when wrapping Request instance
- Fix: documentation update
## v1.6.0
- Enhance: added `res.buffer()` api for convenience, it returns body as a Node.js buffer
- Enhance: better old server support by handling raw deflate response

@@ -16,3 +22,3 @@ - Enhance: skip encoding detection for non-HTML/XML response

- Fix: HEAD request doesn't need decompression, as body is empty
- Fix: req.body now accepts a Node.js buffer
- Fix: `req.body` now accepts a Node.js buffer

@@ -23,3 +29,3 @@ ## v1.5.3

- Fix: allow resolving response and cloned response in any order
- Fix: avoid setting content-length when form-data body use streams
- Fix: avoid setting `content-length` when `form-data` body use streams
- Fix: send DELETE request with content-length when body is present

@@ -73,3 +79,3 @@ - Fix: allow any url when calling new Request, but still reject non-http(s) url in fetch

- Enhance: now fetch.Request is exposed as well
- Enhance: now `fetch.Request` is exposed as well

@@ -103,3 +109,3 @@ ## v1.2.1

- Fix: when follow = 0, fetch should not follow redirect
- Fix: when `follow = 0`, fetch should not follow redirect
- Enhance: update tests for better coverage

@@ -106,0 +112,0 @@ - Enhance: code formatting

@@ -232,2 +232,3 @@

// accept string, buffer or readable stream as body
// per spec we will call tostring on non-stream objects
if (typeof options.body === 'string') {

@@ -241,2 +242,5 @@ req.write(options.body);

options.body.pipe(req);
} else if (typeof options.body === 'object') {
req.write(options.body.toString());
req.end();
} else {

@@ -243,0 +247,0 @@ req.end();

@@ -50,3 +50,3 @@

input.compress : true;
this.counter = init.counter || input.counter || input.follow || 0;
this.counter = init.counter || input.counter || 0;
this.agent = init.agent || input.agent;

@@ -53,0 +53,0 @@

@@ -7,5 +7,5 @@

- Topics such as cross-origin, content security policy, mixed content, service workers are ignored, given our server-side context.
- Topics such as Cross-Origin, Content Security Policy, Mixed Content, Service Workers are ignored, given our server-side context.
- Url input must be an absolute url, using either `http` or `https` as scheme.
- URL input must be an absolute URL, using either `http` or `https` as scheme.

@@ -23,1 +23,7 @@ - On the upside, there are no forbidden headers, and `res.url` contains the final url when following redirects.

- There is currently no built-in caching, as server-side caching varies by use-cases.
- Current implementation lacks server-side cookie store, you will need to extract `Set-Cookie` headers manually.
- If you are using `res.clone()` and writing an isomorphic app, note that stream on Node.js have a smaller internal buffer size (16Kb, aka `highWaterMark`) from client-side browsers (>1Mb, not consistent across browsers).
- ES6 features such as `headers.entries()` are missing at the moment, but you can use `headers.raw()` to retrieve the raw headers object.
{
"name": "node-fetch",
"version": "1.6.0",
"version": "1.6.1",
"description": "A light-weight module that brings window.fetch to node.js and io.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -67,4 +67,23 @@

// since v1.6.0, there is also res.buffer() for convenience
// stream
// the node.js way is to use stream when possible
fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png')
.then(function(res) {
var dest = fs.createWriteStream('./octocat.png');
res.body.pipe(dest);
});
// buffer
// if you prefer to cache binary data in full, use buffer()
// note that buffer() is a node-fetch only API
var fileType = require('file-type');
fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png')
.then(function(res) {
return res.buffer();
}).then(function(buffer) {
fileType(buffer);
});
// meta

@@ -114,3 +133,3 @@

// post with form-data (custom headers)
// note that getHeaders() is non-standard api
// note that getHeaders() is non-standard API

@@ -158,5 +177,5 @@ var FormData = require('form-data');

, headers: {} // request header. format {a:'1'} or {b:['1','2','3']}
, redirect: 'follow' // set to 'manual' to extract redirect headers, `error` to reject redirect
, redirect: 'follow' // set to `manual` to extract redirect headers, `error` to reject redirect
, follow: 20 // maximum redirect count. 0 to not follow redirect
, timeout: 0 // req/res timeout in ms. 0 to disable (os limit still applies), timeout reset on redirect
, timeout: 0 // req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies)
, compress: true // support gzip/deflate content encoding. false to disable

@@ -163,0 +182,0 @@ , size: 0 // maximum response body size in bytes. 0 to disable

@@ -282,3 +282,3 @@

it('should obey maximum redirect', function() {
it('should obey maximum redirect, reject case', function() {
url = base + '/redirect/chain';

@@ -293,2 +293,13 @@ opts = {

it('should obey redirect chain, resolve case', function() {
url = base + '/redirect/chain';
opts = {
follow: 2
}
return fetch(url, opts).then(function(res) {
expect(res.url).to.equal(base + '/inspect');
expect(res.status).to.equal(200);
});
});
it('should allow not following redirect', function() {

@@ -721,2 +732,17 @@ url = base + '/redirect/301';

it('should allow POST request with object body', function() {
url = base + '/inspect';
// note that fetch simply calls tostring on an object
opts = {
method: 'POST'
, body: { a:1 }
};
return fetch(url, opts).then(function(res) {
return res.json();
}).then(function(res) {
expect(res.method).to.equal('POST');
expect(res.body).to.equal('[object Object]');
});
});
it('should allow PUT request', function() {

@@ -1145,2 +1171,3 @@ url = base + '/inspect';

res.l = false;
res.m = new Buffer('test');

@@ -1165,2 +1192,3 @@ var h1 = new Headers(res);

expect(h1._headers['l']).to.be.undefined;
expect(h1._headers['m']).to.be.undefined;

@@ -1224,2 +1252,4 @@ expect(h1._headers['z']).to.be.undefined;

expect(r2.follow).to.equal(2);
expect(r1.counter).to.equal(0);
expect(r2.counter).to.equal(0);
});

@@ -1334,2 +1364,7 @@

it('should default to 200 as status code', function() {
var res = new Response(null);
expect(res.status).to.equal(200);
});
it('should support parsing headers in Request constructor', function() {

@@ -1409,3 +1444,3 @@ url = base;

expect(cl.method).to.equal('POST');
expect(cl.counter).to.equal(3);
expect(cl.counter).to.equal(0);
expect(cl.agent).to.equal(agent);

@@ -1412,0 +1447,0 @@ // clone body shouldn't be the same body

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc