@whatwg-node/node-fetch 0.5.17-alpha-20240726115125-ab31308a7b0579cdd0a19007f92db672cf1eaa85 → 0.5.17-alpha-20240726134754-26685fa50fbd65870b6d37a899c8498890fe3783

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/Request.js CHANGED
@@ -2,6 +2,8 @@
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.PonyfillRequest = void 0;
5
+ const http_1 = require("http");
6
+ const https_1 = require("https");
5
7
  const Body_js_1 = require("./Body.js");
6
8
  const Headers_js_1 = require("./Headers.js");
7
9
  function isRequest(input) {
@@ -75,6 +77,22 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
75
77
  this.contentLength = parseInt(contentLengthInHeaders, 10);
76
78
  }
77
79
  }
80
+ this._agent = requestInit?.agent;
81
+ }
82
+ get agent() {
83
+ if (this._agent != null) {
84
+ return this._agent;
85
+ }
86
+ // Disable agent when running in jest
87
+ if (globalThis['libcurl'] || typeof jest === 'object') {
88
+ return false;
89
+ }
90
+ if (this.url.startsWith('http:')) {
91
+ return http_1.globalAgent;
92
+ }
93
+ else if (this.url.startsWith('https:')) {
94
+ return https_1.globalAgent;
95
+ }
78
96
  }
79
97
  get signal() {
80
98
  // Create a new signal only if needed
package/esm/Request.js CHANGED
@@ -1,4 +1,6 @@
1
1
  var _a;
2
+ import { globalAgent as httpGlobalAgent } from 'http';
3
+ import { globalAgent as httpsGlobalAgent } from 'https';
2
4
  import { PonyfillBody } from './Body.js';
3
5
  import { isHeadersLike, PonyfillHeaders } from './Headers.js';
4
6
  function isRequest(input) {
@@ -72,6 +74,22 @@ export class PonyfillRequest extends PonyfillBody {
72
74
  this.contentLength = parseInt(contentLengthInHeaders, 10);
73
75
  }
74
76
  }
77
+ this._agent = requestInit?.agent;
78
+ }
79
+ get agent() {
80
+ if (this._agent != null) {
81
+ return this._agent;
82
+ }
83
+ // Disable agent when running in jest
84
+ if (globalThis['libcurl'] || typeof jest === 'object') {
85
+ return false;
86
+ }
87
+ if (this.url.startsWith('http:')) {
88
+ return httpGlobalAgent;
89
+ }
90
+ else if (this.url.startsWith('https:')) {
91
+ return httpsGlobalAgent;
92
+ }
75
93
  }
76
94
  get signal() {
77
95
  // Create a new signal only if needed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.17-alpha-20240726115125-ab31308a7b0579cdd0a19007f92db672cf1eaa85",
3
+ "version": "0.5.17-alpha-20240726134754-26685fa50fbd65870b6d37a899c8498890fe3783",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -1,4 +1,5 @@
1
- import { Agent } from 'http';
1
+ import { Agent as HTTPAgent } from 'http';
2
+ import { Agent as HTTPSAgent } from 'https';
2
3
  import { BodyPonyfillInit, PonyfillBody, PonyfillBodyOptions } from './Body.cjs';
3
4
  import { PonyfillHeadersInit } from './Headers.cjs';
4
5
  export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body' | 'headers'> & {
@@ -6,7 +7,7 @@ export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body'
6
7
  duplex?: 'half' | 'full';
7
8
  headers?: PonyfillHeadersInit;
8
9
  headersSerializer?: HeadersSerializer;
9
- agent?: Agent;
10
+ agent?: HTTPAgent | HTTPSAgent | false;
10
11
  };
11
12
  type HeadersSerializer = (headers: Headers, onContentLength?: (contentLength: string) => void) => string[];
12
13
  export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> implements Request {
@@ -25,8 +26,9 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
25
26
  referrer: string;
26
27
  referrerPolicy: ReferrerPolicy;
27
28
  url: string;
28
- agent?: Agent;
29
29
  duplex: 'half' | 'full';
30
+ private _agent;
31
+ get agent(): false | HTTPAgent | undefined;
30
32
  private _signal;
31
33
  get signal(): AbortSignal;
32
34
  clone(): PonyfillRequest<TJSON>;
@@ -1,4 +1,5 @@
1
- import { Agent } from 'http';
1
+ import { Agent as HTTPAgent } from 'http';
2
+ import { Agent as HTTPSAgent } from 'https';
2
3
  import { BodyPonyfillInit, PonyfillBody, PonyfillBodyOptions } from './Body.js';
3
4
  import { PonyfillHeadersInit } from './Headers.js';
4
5
  export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body' | 'headers'> & {
@@ -6,7 +7,7 @@ export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body'
6
7
  duplex?: 'half' | 'full';
7
8
  headers?: PonyfillHeadersInit;
8
9
  headersSerializer?: HeadersSerializer;
9
- agent?: Agent;
10
+ agent?: HTTPAgent | HTTPSAgent | false;
10
11
  };
11
12
  type HeadersSerializer = (headers: Headers, onContentLength?: (contentLength: string) => void) => string[];
12
13
  export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> implements Request {
@@ -25,8 +26,9 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
25
26
  referrer: string;
26
27
  referrerPolicy: ReferrerPolicy;
27
28
  url: string;
28
- agent?: Agent;
29
29
  duplex: 'half' | 'full';
30
+ private _agent;
31
+ get agent(): false | HTTPAgent | undefined;
30
32
  private _signal;
31
33
  get signal(): AbortSignal;
32
34
  clone(): PonyfillRequest<TJSON>;