Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@whatwg-node/fetch

Package Overview
Dependencies
Maintainers
1
Versions
475
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@whatwg-node/fetch - npm Package Compare versions

Comparing version 0.4.6-alpha-20220927125913-2297df6 to 0.4.6-alpha-20220927131110-4cfdcdb

7

CHANGELOG.md
# @whatwg-node/fetch
## 0.4.6-alpha-20220927125913-2297df6
## 0.4.6-alpha-20220927131110-4cfdcdb

@@ -9,7 +9,2 @@ ### Patch Changes

- [#148](https://github.com/ardatan/whatwg-node/pull/148) [`c8bc88a`](https://github.com/ardatan/whatwg-node/commit/c8bc88ac49716c721200ea5546d8b0f99093ad9f) Thanks [@ardatan](https://github.com/ardatan)! - - On Node 14, fix the return method of Response.body's AsyncIterator to close HTTP connection correctly
- On Node 14, handle ReadableStream's cancel correctly if Response.body is a ReadableStream
- Do not modify ReadableStream.cancel's behavior but handle it internally
- On Node 18, do not combine Response.body's return and AbortController which causes a memory leak
## 0.4.5

@@ -16,0 +11,0 @@

95

dist/create-node-ponyfill.js
const handleFileRequest = require("./handle-file-request");
const readableStreamToReadable = require("./readableStreamToReadable");

@@ -83,2 +82,45 @@ module.exports = function createNodePonyfill(opts = {}) {

// ReadableStream doesn't handle aborting properly, so we need to patch it
ponyfills.ReadableStream = class PonyfillReadableStream extends ponyfills.ReadableStream {
constructor(underlyingSource, ...opts) {
super({
...underlyingSource,
cancel: (e) => {
this.cancelled = true;
if (underlyingSource.cancel) {
return underlyingSource.cancel(e);
}
}
}, ...opts);
this.underlyingSource = underlyingSource;
}
[Symbol.asyncIterator]() {
const asyncIterator = super[Symbol.asyncIterator]();
return {
next: (...args) => asyncIterator.next(...args),
throw: (...args) => asyncIterator.throw(...args),
return: async (e) => {
const originalResult = await asyncIterator.return(e);
if (!this.cancelled) {
this.cancelled = true;
if (this.underlyingSource.cancel) {
await this.underlyingSource.cancel(e);
}
}
return originalResult;
}
}
}
async cancel(e) {
const originalResult = !super.locked && await super.cancel(e);
if (!this.cancelled) {
this.cancelled = true;
if (this.underlyingSource.cancel) {
await this.underlyingSource.cancel(e);
}
}
return originalResult;
}
}
if (!ponyfills.crypto) {

@@ -214,3 +256,3 @@ const cryptoModule = require("crypto");

if (options.body[Symbol.toStringTag] === 'ReadableStream') {
options.body = readableStreamToReadable(options.body);
options.body = streams.Readable.fromWeb ? streams.Readable.fromWeb(options.body) : streams.Readable.from(options.body);
}

@@ -233,39 +275,3 @@ }

}
const abortCtrl = new ponyfills.AbortController();
return realFetch(requestOrUrl, {
...options,
signal: abortCtrl.signal
}).then(res => {
return new Proxy(res, {
get(target, prop, receiver) {
if (prop === 'body') {
return new Proxy(res.body, {
get(target, prop, receiver) {
if (prop === Symbol.asyncIterator) {
return () => {
const originalAsyncIterator = target[Symbol.asyncIterator]();
return {
next() {
return originalAsyncIterator.next();
},
return() {
abortCtrl.abort();
return originalAsyncIterator.return();
},
throw(error) {
abortCtrl.abort(error);
return originalAsyncIterator.throw(error);
}
}
}
}
return Reflect.get(target, prop, receiver);
}
})
}
return Reflect.get(target, prop, receiver);
}
})
});
return realFetch(requestOrUrl);
};

@@ -278,3 +284,12 @@

if (body != null && body[Symbol.toStringTag] === 'ReadableStream') {
const actualBody = readableStreamToReadable(body);
const actualBody = streams.Readable.fromWeb ? streams.Readable.fromWeb(body) : streams.Readable.from(body, {
emitClose: true,
autoDestroy: true,
});
actualBody.on('pause', () => {
body.cancel();
})
actualBody.on('close', () => {
body.cancel();
})
// Polyfill ReadableStream is not working well with node-fetch's Response

@@ -281,0 +296,0 @@ return new OriginalResponse(actualBody, init);

{
"name": "@whatwg-node/fetch",
"version": "0.4.6-alpha-20220927125913-2297df6",
"version": "0.4.6-alpha-20220927131110-4cfdcdb",
"description": "Cross Platform Smart Fetch Ponyfill",

@@ -5,0 +5,0 @@ "author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",

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