@whatwg-node/node-fetch 0.5.0-alpha-20230530162136-224230c → 0.5.0-alpha-20230530165828-26d634c

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.
Files changed (3) hide show
  1. package/cjs/fetch.js +48 -25
  2. package/esm/fetch.js +25 -25
  3. package/package.json +1 -1
package/cjs/fetch.js CHANGED
@@ -1,12 +1,34 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.fetchPonyfill = void 0;
4
27
  const fs_1 = require("fs");
5
28
  const stream_1 = require("stream");
6
29
  const url_1 = require("url");
7
- const node_libcurl_1 = require("node-libcurl");
8
- const fetch_1 = require("@whatwg-node/fetch");
9
30
  const Blob_js_1 = require("./Blob.js");
31
+ const Headers_js_1 = require("./Headers.js");
10
32
  const Request_js_1 = require("./Request.js");
11
33
  const Response_js_1 = require("./Response.js");
12
34
  const URL_js_1 = require("./URL.js");
@@ -36,7 +58,7 @@ function getResponseForDataUri(url) {
36
58
  });
37
59
  }
38
60
  const BASE64_SUFFIX = ';base64';
39
- function fetchPonyfill(info, init) {
61
+ async function fetchPonyfill(info, init) {
40
62
  if (typeof info === 'string' || 'href' in info) {
41
63
  const ponyfillRequest = new Request_js_1.PonyfillRequest(info, init);
42
64
  return fetchPonyfill(ponyfillRequest);
@@ -57,7 +79,7 @@ function fetchPonyfill(info, init) {
57
79
  : stream_1.Readable.from(fetchRequest.body)
58
80
  : null);
59
81
  const curlyHeaders = [];
60
- let size = undefined;
82
+ let size;
61
83
  fetchRequest.headers.forEach((value, key) => {
62
84
  curlyHeaders.push(`${key}: ${value}`);
63
85
  if (key === 'content-length') {
@@ -70,6 +92,7 @@ function fetchPonyfill(info, init) {
70
92
  curlyResponseBodyParser: false,
71
93
  upload: nodeReadable != null,
72
94
  transferEncoding: false,
95
+ httpTransferDecoding: true,
73
96
  curlyStreamUpload: nodeReadable,
74
97
  // this will just make libcurl use their own progress function (which is pretty neat)
75
98
  // curlyProgressCallback() { return CurlProgressFunc.Continue },
@@ -80,28 +103,28 @@ function fetchPonyfill(info, init) {
80
103
  if (size != null) {
81
104
  curlyOptions.inFileSize = size;
82
105
  }
83
- return node_libcurl_1.curly[fetchRequest.method.toLowerCase()](fetchRequest.url, curlyOptions).then(curlyResult => {
84
- const responseHeaders = new fetch_1.Headers();
85
- curlyResult.headers.forEach(headerInfo => {
86
- for (const key in headerInfo) {
87
- if (key !== 'result') {
88
- responseHeaders.append(key, headerInfo[key]);
89
- }
90
- }
91
- });
92
- curlyResult.data.on('error', (err) => {
93
- if (err.isCurlError && err.code === node_libcurl_1.CurlCode.CURLE_ABORTED_BY_CALLBACK) {
94
- // this is expected
106
+ const { curly, CurlCode } = await Promise.resolve().then(() => __importStar(require('node-libcurl')));
107
+ const curlyResult = await curly(fetchRequest.url, curlyOptions);
108
+ const responseHeaders = new Headers_js_1.PonyfillHeaders();
109
+ curlyResult.headers.forEach(headerInfo => {
110
+ for (const key in headerInfo) {
111
+ if (key !== 'result') {
112
+ responseHeaders.append(key, headerInfo[key]);
95
113
  }
96
- else {
97
- throw err;
98
- }
99
- });
100
- return new Response_js_1.PonyfillResponse(curlyResult.data, {
101
- status: curlyResult.statusCode,
102
- headers: responseHeaders,
103
- url: info.url,
104
- });
114
+ }
115
+ });
116
+ curlyResult.data.on('error', (err) => {
117
+ if (err.isCurlError && err.code === CurlCode.CURLE_ABORTED_BY_CALLBACK) {
118
+ // this is expected
119
+ }
120
+ else {
121
+ throw err;
122
+ }
123
+ });
124
+ return new Response_js_1.PonyfillResponse(curlyResult.data, {
125
+ status: curlyResult.statusCode,
126
+ headers: responseHeaders,
127
+ url: info.url,
105
128
  });
106
129
  }
107
130
  exports.fetchPonyfill = fetchPonyfill;
package/esm/fetch.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { createReadStream } from 'fs';
2
2
  import { Readable } from 'stream';
3
3
  import { fileURLToPath } from 'url';
4
- import { CurlCode, curly } from 'node-libcurl';
5
- import { Headers } from '@whatwg-node/fetch';
6
4
  import { PonyfillBlob } from './Blob.js';
5
+ import { PonyfillHeaders } from './Headers.js';
7
6
  import { PonyfillRequest } from './Request.js';
8
7
  import { PonyfillResponse } from './Response.js';
9
8
  import { PonyfillURL } from './URL.js';
@@ -33,7 +32,7 @@ function getResponseForDataUri(url) {
33
32
  });
34
33
  }
35
34
  const BASE64_SUFFIX = ';base64';
36
- export function fetchPonyfill(info, init) {
35
+ export async function fetchPonyfill(info, init) {
37
36
  if (typeof info === 'string' || 'href' in info) {
38
37
  const ponyfillRequest = new PonyfillRequest(info, init);
39
38
  return fetchPonyfill(ponyfillRequest);
@@ -54,7 +53,7 @@ export function fetchPonyfill(info, init) {
54
53
  : Readable.from(fetchRequest.body)
55
54
  : null);
56
55
  const curlyHeaders = [];
57
- let size = undefined;
56
+ let size;
58
57
  fetchRequest.headers.forEach((value, key) => {
59
58
  curlyHeaders.push(`${key}: ${value}`);
60
59
  if (key === 'content-length') {
@@ -67,6 +66,7 @@ export function fetchPonyfill(info, init) {
67
66
  curlyResponseBodyParser: false,
68
67
  upload: nodeReadable != null,
69
68
  transferEncoding: false,
69
+ httpTransferDecoding: true,
70
70
  curlyStreamUpload: nodeReadable,
71
71
  // this will just make libcurl use their own progress function (which is pretty neat)
72
72
  // curlyProgressCallback() { return CurlProgressFunc.Continue },
@@ -77,27 +77,27 @@ export function fetchPonyfill(info, init) {
77
77
  if (size != null) {
78
78
  curlyOptions.inFileSize = size;
79
79
  }
80
- return curly[fetchRequest.method.toLowerCase()](fetchRequest.url, curlyOptions).then(curlyResult => {
81
- const responseHeaders = new Headers();
82
- curlyResult.headers.forEach(headerInfo => {
83
- for (const key in headerInfo) {
84
- if (key !== 'result') {
85
- responseHeaders.append(key, headerInfo[key]);
86
- }
80
+ const { curly, CurlCode } = await import('node-libcurl');
81
+ const curlyResult = await curly(fetchRequest.url, curlyOptions);
82
+ const responseHeaders = new PonyfillHeaders();
83
+ curlyResult.headers.forEach(headerInfo => {
84
+ for (const key in headerInfo) {
85
+ if (key !== 'result') {
86
+ responseHeaders.append(key, headerInfo[key]);
87
87
  }
88
- });
89
- curlyResult.data.on('error', (err) => {
90
- if (err.isCurlError && err.code === CurlCode.CURLE_ABORTED_BY_CALLBACK) {
91
- // this is expected
92
- }
93
- else {
94
- throw err;
95
- }
96
- });
97
- return new PonyfillResponse(curlyResult.data, {
98
- status: curlyResult.statusCode,
99
- headers: responseHeaders,
100
- url: info.url,
101
- });
88
+ }
89
+ });
90
+ curlyResult.data.on('error', (err) => {
91
+ if (err.isCurlError && err.code === CurlCode.CURLE_ABORTED_BY_CALLBACK) {
92
+ // this is expected
93
+ }
94
+ else {
95
+ throw err;
96
+ }
97
+ });
98
+ return new PonyfillResponse(curlyResult.data, {
99
+ status: curlyResult.statusCode,
100
+ headers: responseHeaders,
101
+ url: info.url,
102
102
  });
103
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.0-alpha-20230530162136-224230c",
3
+ "version": "0.5.0-alpha-20230530165828-26d634c",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {