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-20220927131110-4cfdcdb to 0.4.6-alpha-20220927134607-bd5c990

dist/readableStreamToReadable.js

7

CHANGELOG.md
# @whatwg-node/fetch
## 0.4.6-alpha-20220927131110-4cfdcdb
## 0.4.6-alpha-20220927134607-bd5c990

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

- [#148](https://github.com/ardatan/whatwg-node/pull/148) [`eb10500`](https://github.com/ardatan/whatwg-node/commit/eb105005fd01bd227eff8d52c22b39ea1a8c6700) 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

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

95

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

@@ -82,45 +83,2 @@ 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) {

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

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

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

}
return realFetch(requestOrUrl);
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);
}
})
});
};

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

if (body != null && body[Symbol.toStringTag] === 'ReadableStream') {
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();
})
const actualBody = readableStreamToReadable(body);
// Polyfill ReadableStream is not working well with node-fetch's Response

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

{
"name": "@whatwg-node/fetch",
"version": "0.4.6-alpha-20220927131110-4cfdcdb",
"version": "0.4.6-alpha-20220927134607-bd5c990",
"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