@whatwg-node/node-fetch 0.5.0-alpha-20230531122910-f56e992 → 0.5.0-alpha-20230531142534-b373f43

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/fetch.js CHANGED
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.fetchPonyfill = void 0;
27
+ /* eslint-disable @typescript-eslint/no-this-alias */
27
28
  const fs_1 = require("fs");
28
29
  const stream_1 = require("stream");
29
30
  const url_1 = require("url");
@@ -86,13 +87,23 @@ async function fetchPonyfill(info, init) {
86
87
  size = Number(value);
87
88
  }
88
89
  });
90
+ let easyNativeBinding;
89
91
  const curlyOptions = {
90
92
  // we want the unparsed binary response to be returned as a stream to us
91
93
  curlyStreamResponse: true,
92
94
  curlyResponseBodyParser: false,
95
+ curlyProgressCallback() {
96
+ if (easyNativeBinding == null) {
97
+ easyNativeBinding = this;
98
+ }
99
+ return fetchRequest.signal.aborted ? 1 : 0;
100
+ },
93
101
  upload: nodeReadable != null,
94
102
  transferEncoding: false,
95
103
  httpTransferDecoding: true,
104
+ followLocation: fetchRequest.redirect === 'follow',
105
+ maxRedirs: 20,
106
+ acceptEncoding: '',
96
107
  curlyStreamUpload: nodeReadable,
97
108
  // this will just make libcurl use their own progress function (which is pretty neat)
98
109
  // curlyProgressCallback() { return CurlProgressFunc.Continue },
@@ -103,11 +114,19 @@ async function fetchPonyfill(info, init) {
103
114
  if (size != null) {
104
115
  curlyOptions.inFileSize = size;
105
116
  }
106
- const { curly, CurlCode } = await Promise.resolve().then(() => __importStar(require('node-libcurl')));
117
+ const { curly, CurlCode, CurlPause } = await Promise.resolve().then(() => __importStar(require('node-libcurl')));
118
+ fetchRequest.signal.onabort = () => {
119
+ if (easyNativeBinding != null) {
120
+ easyNativeBinding.pause(CurlPause.Recv);
121
+ }
122
+ };
107
123
  const curlyResult = await curly(fetchRequest.url, curlyOptions);
108
124
  const responseHeaders = new Headers_js_1.PonyfillHeaders();
109
125
  curlyResult.headers.forEach(headerInfo => {
110
126
  for (const key in headerInfo) {
127
+ if (key === 'location' || (key === 'Location' && fetchRequest.redirect === 'error')) {
128
+ throw new Error('redirects are not allowed');
129
+ }
111
130
  if (key !== 'result') {
112
131
  responseHeaders.append(key, headerInfo[key]);
113
132
  }
package/esm/fetch.js CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-this-alias */
1
2
  import { createReadStream } from 'fs';
2
3
  import { Readable } from 'stream';
3
4
  import { fileURLToPath } from 'url';
@@ -60,13 +61,23 @@ export async function fetchPonyfill(info, init) {
60
61
  size = Number(value);
61
62
  }
62
63
  });
64
+ let easyNativeBinding;
63
65
  const curlyOptions = {
64
66
  // we want the unparsed binary response to be returned as a stream to us
65
67
  curlyStreamResponse: true,
66
68
  curlyResponseBodyParser: false,
69
+ curlyProgressCallback() {
70
+ if (easyNativeBinding == null) {
71
+ easyNativeBinding = this;
72
+ }
73
+ return fetchRequest.signal.aborted ? 1 : 0;
74
+ },
67
75
  upload: nodeReadable != null,
68
76
  transferEncoding: false,
69
77
  httpTransferDecoding: true,
78
+ followLocation: fetchRequest.redirect === 'follow',
79
+ maxRedirs: 20,
80
+ acceptEncoding: '',
70
81
  curlyStreamUpload: nodeReadable,
71
82
  // this will just make libcurl use their own progress function (which is pretty neat)
72
83
  // curlyProgressCallback() { return CurlProgressFunc.Continue },
@@ -77,11 +88,19 @@ export async function fetchPonyfill(info, init) {
77
88
  if (size != null) {
78
89
  curlyOptions.inFileSize = size;
79
90
  }
80
- const { curly, CurlCode } = await import('node-libcurl');
91
+ const { curly, CurlCode, CurlPause } = await import('node-libcurl');
92
+ fetchRequest.signal.onabort = () => {
93
+ if (easyNativeBinding != null) {
94
+ easyNativeBinding.pause(CurlPause.Recv);
95
+ }
96
+ };
81
97
  const curlyResult = await curly(fetchRequest.url, curlyOptions);
82
98
  const responseHeaders = new PonyfillHeaders();
83
99
  curlyResult.headers.forEach(headerInfo => {
84
100
  for (const key in headerInfo) {
101
+ if (key === 'location' || (key === 'Location' && fetchRequest.redirect === 'error')) {
102
+ throw new Error('redirects are not allowed');
103
+ }
85
104
  if (key !== 'result') {
86
105
  responseHeaders.append(key, headerInfo[key]);
87
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.0-alpha-20230531122910-f56e992",
3
+ "version": "0.5.0-alpha-20230531142534-b373f43",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {