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

@whatwg-node/node-fetch

Package Overview
Dependencies
Maintainers
1
Versions
509
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@whatwg-node/node-fetch - npm Package Compare versions

Comparing version 0.5.16 to 0.5.17-alpha-20240726115055-bdfd2ddb1d096b6926c00d7ab31d543ea1ddd058

31

cjs/fetchCurl.js

@@ -84,3 +84,14 @@ "use strict";

curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
const pipedStream = stream.pipe(new stream_1.PassThrough());
const outputStream = new stream_1.PassThrough();
stream_1.promises
.pipeline(stream, outputStream, {
end: true,
signal: fetchRequest['_signal'] ?? undefined,
})
.then(() => {
if (!stream.destroyed) {
stream.resume();
}
})
.catch(reject);
const headersFlat = headersBuf

@@ -93,3 +104,6 @@ .toString('utf8')

(headerFilter.includes('location') || headerFilter.includes('Location'))) {
pipedStream.destroy();
if (!stream.destroyed) {
stream.resume();
}
outputStream.destroy();
reject(new Error('redirect is not allowed'));

@@ -102,12 +116,3 @@ }

const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
pipedStream.on('pause', () => {
stream.pause();
});
pipedStream.on('resume', () => {
stream.resume();
});
pipedStream.on('close', () => {
stream.destroy();
});
const ponyfillResponse = new Response_js_1.PonyfillResponse(pipedStream, {
const ponyfillResponse = new Response_js_1.PonyfillResponse(outputStream, {
status,

@@ -118,3 +123,3 @@ headers: headersInit,

resolve(ponyfillResponse);
streamResolved = pipedStream;
streamResolved = outputStream;
});

@@ -121,0 +126,0 @@ curlHandle.perform();

@@ -8,3 +8,2 @@ "use strict";

const zlib_1 = require("zlib");
const AbortError_js_1 = require("./AbortError.js");
const Request_js_1 = require("./Request.js");

@@ -44,3 +43,3 @@ const Response_js_1 = require("./Response.js");

nodeRequest.once('response', nodeResponse => {
let responseBody = nodeResponse;
let outputStream;
const contentEncoding = nodeResponse.headers['content-encoding'];

@@ -50,15 +49,17 @@ switch (contentEncoding) {

case 'gzip':
responseBody = nodeResponse.pipe((0, zlib_1.createGunzip)());
outputStream = (0, zlib_1.createGunzip)();
break;
case 'x-deflate':
case 'deflate':
responseBody = nodeResponse.pipe((0, zlib_1.createInflate)());
outputStream = (0, zlib_1.createInflate)();
break;
case 'x-deflate-raw':
case 'deflate-raw':
responseBody = nodeResponse.pipe((0, zlib_1.createInflateRaw)());
outputStream = (0, zlib_1.createInflateRaw)();
break;
case 'br':
responseBody = nodeResponse.pipe((0, zlib_1.createBrotliDecompress)());
outputStream = (0, zlib_1.createBrotliDecompress)();
break;
default:
outputStream = new stream_1.PassThrough();
}

@@ -83,21 +84,14 @@ if (nodeResponse.headers.location) {

}
if (responseBody === nodeResponse) {
responseBody = nodeResponse.pipe(new stream_1.PassThrough());
responseBody.on('pause', () => {
nodeResponse.pause();
});
responseBody.on('resume', () => {
stream_1.promises
.pipeline(nodeResponse, outputStream, {
signal: fetchRequest['_signal'] ?? undefined,
end: true,
})
.then(() => {
if (!nodeResponse.destroyed) {
nodeResponse.resume();
});
responseBody.on('close', () => {
nodeResponse.destroy();
});
fetchRequest['_signal']?.addEventListener('abort', () => {
if (!nodeResponse.destroyed) {
responseBody.emit('error', new AbortError_js_1.PonyfillAbortError());
}
});
}
nodeResponse.once('error', reject);
const ponyfillResponse = new Response_js_1.PonyfillResponse(responseBody, {
}
})
.catch(reject);
const ponyfillResponse = new Response_js_1.PonyfillResponse(outputStream, {
status: nodeResponse.statusCode,

@@ -104,0 +98,0 @@ statusText: nodeResponse.statusMessage,

@@ -1,2 +0,2 @@

import { PassThrough, Readable } from 'stream';
import { PassThrough, Readable, promises as streamPromises } from 'stream';
import { PonyfillResponse } from './Response.js';

@@ -81,3 +81,14 @@ import { defaultHeadersSerializer, isNodeReadable } from './utils.js';

curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
const pipedStream = stream.pipe(new PassThrough());
const outputStream = new PassThrough();
streamPromises
.pipeline(stream, outputStream, {
end: true,
signal: fetchRequest['_signal'] ?? undefined,
})
.then(() => {
if (!stream.destroyed) {
stream.resume();
}
})
.catch(reject);
const headersFlat = headersBuf

@@ -90,3 +101,6 @@ .toString('utf8')

(headerFilter.includes('location') || headerFilter.includes('Location'))) {
pipedStream.destroy();
if (!stream.destroyed) {
stream.resume();
}
outputStream.destroy();
reject(new Error('redirect is not allowed'));

@@ -99,12 +113,3 @@ }

const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
pipedStream.on('pause', () => {
stream.pause();
});
pipedStream.on('resume', () => {
stream.resume();
});
pipedStream.on('close', () => {
stream.destroy();
});
const ponyfillResponse = new PonyfillResponse(pipedStream, {
const ponyfillResponse = new PonyfillResponse(outputStream, {
status,

@@ -115,3 +120,3 @@ headers: headersInit,

resolve(ponyfillResponse);
streamResolved = pipedStream;
streamResolved = outputStream;
});

@@ -118,0 +123,0 @@ curlHandle.perform();

import { request as httpRequest } from 'http';
import { request as httpsRequest } from 'https';
import { PassThrough, Readable } from 'stream';
import { PassThrough, Readable, promises as streamPromises } from 'stream';
import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'zlib';
import { PonyfillAbortError } from './AbortError.js';
import { PonyfillRequest } from './Request.js';

@@ -40,3 +39,3 @@ import { PonyfillResponse } from './Response.js';

nodeRequest.once('response', nodeResponse => {
let responseBody = nodeResponse;
let outputStream;
const contentEncoding = nodeResponse.headers['content-encoding'];

@@ -46,15 +45,17 @@ switch (contentEncoding) {

case 'gzip':
responseBody = nodeResponse.pipe(createGunzip());
outputStream = createGunzip();
break;
case 'x-deflate':
case 'deflate':
responseBody = nodeResponse.pipe(createInflate());
outputStream = createInflate();
break;
case 'x-deflate-raw':
case 'deflate-raw':
responseBody = nodeResponse.pipe(createInflateRaw());
outputStream = createInflateRaw();
break;
case 'br':
responseBody = nodeResponse.pipe(createBrotliDecompress());
outputStream = createBrotliDecompress();
break;
default:
outputStream = new PassThrough();
}

@@ -79,21 +80,14 @@ if (nodeResponse.headers.location) {

}
if (responseBody === nodeResponse) {
responseBody = nodeResponse.pipe(new PassThrough());
responseBody.on('pause', () => {
nodeResponse.pause();
});
responseBody.on('resume', () => {
streamPromises
.pipeline(nodeResponse, outputStream, {
signal: fetchRequest['_signal'] ?? undefined,
end: true,
})
.then(() => {
if (!nodeResponse.destroyed) {
nodeResponse.resume();
});
responseBody.on('close', () => {
nodeResponse.destroy();
});
fetchRequest['_signal']?.addEventListener('abort', () => {
if (!nodeResponse.destroyed) {
responseBody.emit('error', new PonyfillAbortError());
}
});
}
nodeResponse.once('error', reject);
const ponyfillResponse = new PonyfillResponse(responseBody, {
}
})
.catch(reject);
const ponyfillResponse = new PonyfillResponse(outputStream, {
status: nodeResponse.statusCode,

@@ -100,0 +94,0 @@ statusText: nodeResponse.statusMessage,

{
"name": "@whatwg-node/node-fetch",
"version": "0.5.16",
"version": "0.5.17-alpha-20240726115055-bdfd2ddb1d096b6926c00d7ab31d543ea1ddd058",
"description": "Fetch API implementation for Node",

@@ -5,0 +5,0 @@ "sideEffects": false,

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