Socket
Socket
Sign inDemoInstall

node-fetch

Package Overview
Dependencies
Maintainers
2
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 2.5.0 to 2.6.0

6

CHANGELOG.md

@@ -8,2 +8,8 @@

## v2.6.0
- Enhance: `options.agent`, it now accepts a function that returns custom http(s).Agent instance based on current URL, see readme for more information.
- Fix: incorrect `Content-Length` was returned for stream body in 2.5.0 release; note that `node-fetch` doesn't calculate content length for stream body.
- Fix: `Response.url` should return empty string instead of `null` by default.
## v2.5.0

@@ -10,0 +16,0 @@

18

lib/index.es.js

@@ -554,7 +554,5 @@ process.emitWarning("The .es.js file is deprecated. Use .mjs instead.");

*
* @param Mixed instance Response or Request instance
* @param Mixed instance Any options.body input
*/
function extractContentType(body) {
// istanbul ignore if: Currently, because of a guard in Request, body
// can never be null. Included here for completeness.
if (body === null) {

@@ -606,3 +604,2 @@ // body is null

// istanbul ignore if: included for completion

@@ -627,3 +624,3 @@ if (body === null) {

// body is stream
return instance.size || null;
return null;
}

@@ -1077,3 +1074,3 @@ }

get url() {
return this[INTERNALS$1].url;
return this[INTERNALS$1].url || '';
}

@@ -1338,3 +1335,8 @@

if (!headers.has('Connection') && !request.agent) {
let agent = request.agent;
if (typeof agent === 'function') {
agent = agent(parsedURL);
}
if (!headers.has('Connection') && !agent) {
headers.set('Connection', 'close');

@@ -1349,3 +1351,3 @@ }

headers: exportNodeCompatibleHeaders(headers),
agent: request.agent
agent
});

@@ -1352,0 +1354,0 @@ }

@@ -558,7 +558,5 @@ 'use strict';

*
* @param Mixed instance Response or Request instance
* @param Mixed instance Any options.body input
*/
function extractContentType(body) {
// istanbul ignore if: Currently, because of a guard in Request, body
// can never be null. Included here for completeness.
if (body === null) {

@@ -610,3 +608,2 @@ // body is null

// istanbul ignore if: included for completion

@@ -631,3 +628,3 @@ if (body === null) {

// body is stream
return instance.size || null;
return null;
}

@@ -1081,3 +1078,3 @@ }

get url() {
return this[INTERNALS$1].url;
return this[INTERNALS$1].url || '';
}

@@ -1342,3 +1339,8 @@

if (!headers.has('Connection') && !request.agent) {
let agent = request.agent;
if (typeof agent === 'function') {
agent = agent(parsedURL);
}
if (!headers.has('Connection') && !agent) {
headers.set('Connection', 'close');

@@ -1353,3 +1355,3 @@ }

headers: exportNodeCompatibleHeaders(headers),
agent: request.agent
agent
});

@@ -1356,0 +1358,0 @@ }

{
"name": "node-fetch",
"version": "2.5.0",
"version": "2.6.0",
"description": "A light-weight module that brings window.fetch to node.js",

@@ -5,0 +5,0 @@ "main": "lib/index",

@@ -32,2 +32,3 @@ node-fetch

- [Accessing Headers and other Meta data](#accessing-headers-and-other-meta-data)
- [Extract Set-Cookie Header](#extract-set-cookie-header)
- [Post data using a file stream](#post-data-using-a-file-stream)

@@ -212,2 +213,13 @@ - [Post with form-data (detect multipart)](#post-with-form-data-detect-multipart)

#### Extract Set-Cookie Header
Unlike browsers, you can access raw `Set-Cookie` headers manually using `Headers.raw()`, this is a `node-fetch` only API.
```js
fetch(url).then(res => {
// returns an array of values, instead of a string of comma-separated values
console.log(res.headers.raw()['set-cookie']);
});
```
#### Post data using a file stream

@@ -322,3 +334,3 @@

size: 0, // maximum response body size in bytes. 0 to disable
agent: null // http(s).Agent instance, allows custom proxy, certificate, dns lookup etc.
agent: null // http(s).Agent instance or function that returns an instance (see below)
}

@@ -340,2 +352,35 @@ ```

Note: when `body` is a `Stream`, `Content-Length` is not set automatically.
##### Custom Agent
The `agent` option allows you to specify networking related options that's out of the scope of Fetch. Including and not limit to:
- Support self-signed certificate
- Use only IPv4 or IPv6
- Custom DNS Lookup
See [`http.Agent`](https://nodejs.org/api/http.html#http_new_agent_options) for more information.
In addition, `agent` option accepts a function that returns http(s).Agent instance given current [URL](https://nodejs.org/api/url.html), this is useful during a redirection chain across HTTP and HTTPS protocol.
```js
const httpAgent = new http.Agent({
keepAlive: true
});
const httpsAgent = new https.Agent({
keepAlive: true
});
const options = {
agent: function (_parsedURL) {
if (_parsedURL.protocol == 'http:') {
return httpAgent;
} else {
return httpsAgent;
}
}
}
```
<a id="class-request"></a>

@@ -342,0 +387,0 @@ ### Class: Request

Sorry, the diff of this file is not supported yet

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