@whatwg-node/node-fetch 0.5.7-alpha-20240301160930-a3ba2c27f4f23de94960f603ed19b24325dfe24d → 0.5.7-alpha-20240301193514-5a0def1618705c214deaaebc9b385f04b9894f64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/fetchCurl.js CHANGED
@@ -73,6 +73,7 @@ function fetchCurl(fetchRequest) {
73
73
  curlHandle.close();
74
74
  });
75
75
  curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
76
+ const pipedStream = stream.pipe(new node_stream_1.PassThrough());
76
77
  const headersFlat = headersBuf
77
78
  .toString('utf8')
78
79
  .split(/\r?\n|\r/g)
@@ -80,7 +81,7 @@ function fetchCurl(fetchRequest) {
80
81
  if (headerFilter && !headerFilter.startsWith('HTTP/')) {
81
82
  if (fetchRequest.redirect === 'error' &&
82
83
  (headerFilter.includes('location') || headerFilter.includes('Location'))) {
83
- stream.destroy();
84
+ pipedStream.destroy();
84
85
  reject(new Error('redirect is not allowed'));
85
86
  }
86
87
  return true;
@@ -88,7 +89,6 @@ function fetchCurl(fetchRequest) {
88
89
  return false;
89
90
  });
90
91
  const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
91
- const pipedStream = stream.pipe(new node_stream_1.PassThrough());
92
92
  pipedStream.on('pause', () => {
93
93
  stream.pause();
94
94
  });
@@ -104,7 +104,7 @@ function fetchCurl(fetchRequest) {
104
104
  url: fetchRequest.url,
105
105
  });
106
106
  resolve(ponyfillResponse);
107
- streamResolved = stream;
107
+ streamResolved = pipedStream;
108
108
  });
109
109
  curlHandle.perform();
110
110
  });
@@ -5,6 +5,7 @@ const http_1 = require("http");
5
5
  const https_1 = require("https");
6
6
  const stream_1 = require("stream");
7
7
  const zlib_1 = require("zlib");
8
+ const AbortError_js_1 = require("./AbortError.js");
8
9
  const Request_js_1 = require("./Request.js");
9
10
  const Response_js_1 = require("./Response.js");
10
11
  const URL_js_1 = require("./URL.js");
@@ -80,6 +81,11 @@ function fetchNodeHttp(fetchRequest) {
80
81
  responseBody.on('close', () => {
81
82
  nodeResponse.destroy();
82
83
  });
84
+ fetchRequest['_signal']?.addEventListener('abort', () => {
85
+ if (!nodeResponse.destroyed) {
86
+ responseBody.emit('error', new AbortError_js_1.PonyfillAbortError());
87
+ }
88
+ });
83
89
  }
84
90
  const ponyfillResponse = new Response_js_1.PonyfillResponse(responseBody, {
85
91
  status: nodeResponse.statusCode,
package/esm/fetchCurl.js CHANGED
@@ -70,6 +70,7 @@ export function fetchCurl(fetchRequest) {
70
70
  curlHandle.close();
71
71
  });
72
72
  curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
73
+ const pipedStream = stream.pipe(new PassThrough());
73
74
  const headersFlat = headersBuf
74
75
  .toString('utf8')
75
76
  .split(/\r?\n|\r/g)
@@ -77,7 +78,7 @@ export function fetchCurl(fetchRequest) {
77
78
  if (headerFilter && !headerFilter.startsWith('HTTP/')) {
78
79
  if (fetchRequest.redirect === 'error' &&
79
80
  (headerFilter.includes('location') || headerFilter.includes('Location'))) {
80
- stream.destroy();
81
+ pipedStream.destroy();
81
82
  reject(new Error('redirect is not allowed'));
82
83
  }
83
84
  return true;
@@ -85,7 +86,6 @@ export function fetchCurl(fetchRequest) {
85
86
  return false;
86
87
  });
87
88
  const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
88
- const pipedStream = stream.pipe(new PassThrough());
89
89
  pipedStream.on('pause', () => {
90
90
  stream.pause();
91
91
  });
@@ -101,7 +101,7 @@ export function fetchCurl(fetchRequest) {
101
101
  url: fetchRequest.url,
102
102
  });
103
103
  resolve(ponyfillResponse);
104
- streamResolved = stream;
104
+ streamResolved = pipedStream;
105
105
  });
106
106
  curlHandle.perform();
107
107
  });
@@ -2,6 +2,7 @@ import { request as httpRequest } from 'http';
2
2
  import { request as httpsRequest } from 'https';
3
3
  import { PassThrough, Readable } from 'stream';
4
4
  import { createBrotliDecompress, createGunzip, createInflate } from 'zlib';
5
+ import { PonyfillAbortError } from './AbortError.js';
5
6
  import { PonyfillRequest } from './Request.js';
6
7
  import { PonyfillResponse } from './Response.js';
7
8
  import { PonyfillURL } from './URL.js';
@@ -77,6 +78,11 @@ export function fetchNodeHttp(fetchRequest) {
77
78
  responseBody.on('close', () => {
78
79
  nodeResponse.destroy();
79
80
  });
81
+ fetchRequest['_signal']?.addEventListener('abort', () => {
82
+ if (!nodeResponse.destroyed) {
83
+ responseBody.emit('error', new PonyfillAbortError());
84
+ }
85
+ });
80
86
  }
81
87
  const ponyfillResponse = new PonyfillResponse(responseBody, {
82
88
  status: nodeResponse.statusCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.7-alpha-20240301160930-a3ba2c27f4f23de94960f603ed19b24325dfe24d",
3
+ "version": "0.5.7-alpha-20240301193514-5a0def1618705c214deaaebc9b385f04b9894f64",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {