Socket
Socket
Sign inDemoInstall

node-fetch

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-fetch - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

6

CHANGELOG.md

@@ -8,4 +8,8 @@

## v1.3.1 (master)
## v1.3.2 (master)
- Enhance: allow auto detect of form-data input (no `FormData` spec on node.js, this is form-data specific feature)
## v1.3.1
- Enhance: allow custom host header to be set (server-side only feature, as it's a forbidden header on client-side)

@@ -12,0 +16,0 @@

@@ -80,2 +80,7 @@

// detect form data input from form-data module, this hack avoid the need to pass multipart header manually
if (!headers.has('content-type') && options.body && typeof options.body.getBoundary === 'function') {
headers.set('content-type', 'multipart/form-data; boundary=' + options.body.getBoundary());
}
options.headers = headers.raw();

@@ -82,0 +87,0 @@

4

package.json
{
"name": "node-fetch",
"version": "1.3.1",
"version": "1.3.2",
"description": "A light-weight module that brings window.fetch to node.js and io.js",

@@ -31,4 +31,6 @@ "main": "index.js",

"coveralls": "^2.11.2",
"form-data": "^1.0.0-rc1",
"istanbul": "^0.3.5",
"mocha": "^2.1.0",
"parted": "^0.1.1",
"promise": "^6.1.0",

@@ -35,0 +37,0 @@ "resumer": "0.0.0"

@@ -100,3 +100,3 @@

// post with form-data
// post with form-data (detect multipart)

@@ -106,2 +106,14 @@ var FormData = require('form-data');

form.append('a', 1);
fetch('http://httpbin.org/post', { method: 'POST', body: form })
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
});
// post with form-data (custom headers)
var FormData = require('form-data');
var form = new FormData();
form.append('a', 1);
fetch('http://httpbin.org/post', { method: 'POST', body: form, headers: form.getHeaders() })

@@ -108,0 +120,0 @@ .then(function(res) {

@@ -7,2 +7,3 @@

var convert = require('encoding').convert;
var Multipart = require('parted').multipart;

@@ -248,2 +249,20 @@ module.exports = TestServer;

if (p === '/multipart') {
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
var parser = new Multipart(req.headers['content-type']);
var body = '';
parser.on('part', function(field, part) {
body += field + '=' + part;
});
parser.on('end', function() {
res.end(JSON.stringify({
method: req.method,
url: req.url,
headers: req.headers,
body: body
}));
});
req.pipe(parser);
}
}

@@ -12,2 +12,3 @@

var resumer = require('resumer');
var FormData = require('form-data');

@@ -450,2 +451,43 @@ var TestServer = require('./server');

it('should allow POST request with form-data as body', function() {
var form = new FormData();
form.append('a','1');
url = base + '/multipart';
opts = {
method: 'POST'
, body: form
};
return fetch(url, opts).then(function(res) {
return res.json();
}).then(function(res) {
expect(res.method).to.equal('POST');
expect(res.headers['content-type']).to.contain('multipart/form-data');
expect(res.body).to.equal('a=1');
});
});
it('should allow POST request with form-data as body and custom headers', function() {
var form = new FormData();
form.append('a','1');
var headers = form.getHeaders();
headers['b'] = '2';
url = base + '/multipart';
opts = {
method: 'POST'
, body: form
, headers: headers
};
return fetch(url, opts).then(function(res) {
return res.json();
}).then(function(res) {
expect(res.method).to.equal('POST');
expect(res.headers['content-type']).to.contain('multipart/form-data');
expect(res.headers.b).to.equal('2');
expect(res.body).to.equal('a=1');
});
});
it('should allow PUT request', function() {

@@ -452,0 +494,0 @@ url = base + '/inspect';

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc