@comunica/actor-http-fetch 3.3.0 → 4.0.1-alpha.48.0

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/README.md CHANGED
@@ -3,13 +3,12 @@
3
3
  [![npm version](https://badge.fury.io/js/%40comunica%2Factor-http-fetch.svg)](https://www.npmjs.com/package/@comunica/actor-http-fetch)
4
4
 
5
5
  An [HTTP](https://github.com/comunica/comunica/tree/master/packages/bus-http) actor that
6
- uses [cross-fetch](https://www.npmjs.com/package/cross-fetch) to perform HTTP requests.
6
+ uses [fetch](https://fetch.spec.whatwg.org/) to perform HTTP requests.
7
7
 
8
8
  This module is part of the [Comunica framework](https://github.com/comunica/comunica),
9
9
  and should only be used by [developers that want to build their own query engine](https://comunica.dev/docs/modify/).
10
10
 
11
11
  When this actor is used, a custom fetch implementation may be provided via the context (`fetch`).
12
- If none is provided, the default fallback fetch implementation will be used (`node-fetch` in Node.js, and the browser's `fetch` in browser environments).
13
12
 
14
13
  [Click here if you just want to query with Comunica](https://comunica.dev/docs/query/).
15
14
 
@@ -26,7 +25,7 @@ After installing, this package can be added to your engine's configuration as fo
26
25
  {
27
26
  "@context": [
28
27
  ...
29
- "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^3.0.0/components/context.jsonld"
28
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^4.0.0/components/context.jsonld"
30
29
  ],
31
30
  "actors": [
32
31
  ...
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "@context": [
3
- "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^3.0.0/components/context.jsonld",
4
- "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-http/^3.0.0/components/context.jsonld",
5
- "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^3.0.0/components/context.jsonld"
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^4.0.0/components/context.jsonld",
4
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-http/^4.0.0/components/context.jsonld",
5
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^4.0.0/components/context.jsonld"
6
6
  ],
7
7
  "@id": "npmd:@comunica/actor-http-fetch",
8
8
  "components": [
@@ -55,29 +55,37 @@
55
55
  "genericTypeInstances": [
56
56
  {
57
57
  "@type": "ParameterRangeGenericTypeReference",
58
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
58
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
59
59
  },
60
60
  {
61
61
  "@type": "ParameterRangeGenericTypeReference",
62
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
62
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
63
63
  },
64
64
  {
65
65
  "@type": "ParameterRangeGenericTypeReference",
66
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
66
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
67
+ },
68
+ {
69
+ "@type": "ParameterRangeGenericTypeReference",
70
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
67
71
  }
68
72
  ]
69
73
  },
70
74
  {
71
75
  "@type": "ParameterRangeGenericTypeReference",
72
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
76
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
77
+ },
78
+ {
79
+ "@type": "ParameterRangeGenericTypeReference",
80
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
73
81
  },
74
82
  {
75
83
  "@type": "ParameterRangeGenericTypeReference",
76
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
84
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
77
85
  },
78
86
  {
79
87
  "@type": "ParameterRangeGenericTypeReference",
80
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
88
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
81
89
  }
82
90
  ]
83
91
  },
@@ -87,6 +95,20 @@
87
95
  },
88
96
  "comment": "The bus this actor subscribes to."
89
97
  },
98
+ {
99
+ "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_busFailMessage",
100
+ "range": {
101
+ "@type": "ParameterRangeUnion",
102
+ "parameterRangeElements": [
103
+ "xsd:string",
104
+ {
105
+ "@type": "ParameterRangeUndefined"
106
+ }
107
+ ]
108
+ },
109
+ "default": "HTTP request failed: none of the configured actors were able to handle ${action.input}",
110
+ "comment": "The message that will be configured in the bus for reporting failures. This message may be a template string that contains references to the executed `action`. For example, the following templated string is allowed: \"RDF dereferencing failed: no actors could handle ${action.handle.mediaType}\""
111
+ },
90
112
  {
91
113
  "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_beforeActors",
92
114
  "range": {
@@ -100,15 +122,19 @@
100
122
  "genericTypeInstances": [
101
123
  {
102
124
  "@type": "ParameterRangeGenericTypeReference",
103
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
125
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
104
126
  },
105
127
  {
106
128
  "@type": "ParameterRangeGenericTypeReference",
107
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
129
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
108
130
  },
109
131
  {
110
132
  "@type": "ParameterRangeGenericTypeReference",
111
- "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
133
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
134
+ },
135
+ {
136
+ "@type": "ParameterRangeGenericTypeReference",
137
+ "parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
112
138
  }
113
139
  ]
114
140
  }
@@ -173,6 +199,12 @@
173
199
  "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_bus"
174
200
  }
175
201
  },
202
+ {
203
+ "keyRaw": "busFailMessage",
204
+ "value": {
205
+ "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_busFailMessage"
206
+ }
207
+ },
176
208
  {
177
209
  "keyRaw": "beforeActors",
178
210
  "value": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "@context": [
3
- "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^3.0.0/components/context.jsonld"
3
+ "https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^4.0.0/components/context.jsonld"
4
4
  ],
5
5
  "@id": "npmd:@comunica/actor-http-fetch",
6
6
  "@type": "Module",
@@ -3,7 +3,7 @@
3
3
  "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^6.0.0/components/context.jsonld",
4
4
  {
5
5
  "npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
6
- "cahf": "npmd:@comunica/actor-http-fetch/^3.0.0/",
6
+ "cahf": "npmd:@comunica/actor-http-fetch/^4.0.0/",
7
7
  "ActorHttpFetch": {
8
8
  "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch",
9
9
  "@prefix": true,
@@ -17,6 +17,9 @@
17
17
  "args_bus": {
18
18
  "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_bus"
19
19
  },
20
+ "args_busFailMessage": {
21
+ "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_busFailMessage"
22
+ },
20
23
  "args_beforeActors": {
21
24
  "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_beforeActors",
22
25
  "@container": "@list"
@@ -30,6 +33,9 @@
30
33
  "bus": {
31
34
  "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_bus"
32
35
  },
36
+ "busFailMessage": {
37
+ "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_busFailMessage"
38
+ },
33
39
  "beforeActors": {
34
40
  "@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_beforeActors",
35
41
  "@container": "@list"
@@ -1,7 +1,7 @@
1
1
  import type { IActionHttp, IActorHttpOutput, IActorHttpArgs } from '@comunica/bus-http';
2
2
  import { ActorHttp } from '@comunica/bus-http';
3
+ import type { TestResult } from '@comunica/core';
3
4
  import type { IMediatorTypeTime } from '@comunica/mediatortype-time';
4
- import 'cross-fetch/polyfill';
5
5
  /**
6
6
  * A node-fetch actor that listens on the 'init' bus.
7
7
  *
@@ -12,7 +12,7 @@ export declare class ActorHttpFetch extends ActorHttp {
12
12
  private readonly fetchInitPreprocessor;
13
13
  constructor(args: IActorHttpFetchArgs);
14
14
  static createUserAgent(): string;
15
- test(_action: IActionHttp): Promise<IMediatorTypeTime>;
15
+ test(_action: IActionHttp): Promise<TestResult<IMediatorTypeTime>>;
16
16
  /**
17
17
  * Perform a fetch request, taking care of retries
18
18
  * @param fetchFn
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActorHttpFetch = void 0;
4
4
  const bus_http_1 = require("@comunica/bus-http");
5
5
  const context_entries_1 = require("@comunica/context-entries");
6
- require("cross-fetch/polyfill");
6
+ const core_1 = require("@comunica/core");
7
7
  const FetchInitPreprocessor_1 = require("./FetchInitPreprocessor");
8
8
  /**
9
9
  * A node-fetch actor that listens on the 'init' bus.
@@ -22,7 +22,7 @@ class ActorHttpFetch extends bus_http_1.ActorHttp {
22
22
  `Browser-${globalThis.navigator.userAgent}`})`;
23
23
  }
24
24
  async test(_action) {
25
- return { time: Number.POSITIVE_INFINITY };
25
+ return (0, core_1.passTest)({ time: Number.POSITIVE_INFINITY });
26
26
  }
27
27
  /**
28
28
  * Perform a fetch request, taking care of retries
@@ -76,26 +76,25 @@ class ActorHttpFetch extends bus_http_1.ActorHttp {
76
76
  }
77
77
  async run(action) {
78
78
  // Prepare headers
79
- const initHeaders = action.init?.headers ?? {};
80
- action.init = action.init ?? {};
81
- action.init.headers = new Headers(initHeaders);
82
- if (!action.init.headers.has('user-agent')) {
83
- action.init.headers.append('user-agent', this.userAgent);
79
+ const headers = new Headers(action.init?.headers);
80
+ if (!headers.has('User-Agent')) {
81
+ headers.set('User-Agent', this.userAgent);
84
82
  }
85
83
  const authString = action.context.get(context_entries_1.KeysHttp.auth);
86
84
  if (authString) {
87
- action.init.headers.append('Authorization', `Basic ${Buffer.from(authString).toString('base64')}`);
85
+ headers.set('Authorization', `Basic ${Buffer.from(authString).toString('base64')}`);
88
86
  }
87
+ action.init = { ...action.init, headers };
89
88
  // Log request
90
89
  this.logInfo(action.context, `Requesting ${typeof action.input === 'string' ?
91
90
  action.input :
92
91
  action.input.url}`, () => ({
93
- headers: bus_http_1.ActorHttp.headersToHash(new Headers(action.init.headers)),
92
+ headers: bus_http_1.ActorHttp.headersToHash(headers),
94
93
  method: action.init.method ?? 'GET',
95
94
  }));
96
95
  // TODO: remove this workaround once this has a fix: https://github.com/inrupt/solid-client-authn-js/issues/1708
97
96
  if (action.init?.headers && 'append' in action.init.headers && action.context.has(context_entries_1.KeysHttp.fetch)) {
98
- action.init.headers = bus_http_1.ActorHttp.headersToHash(action.init.headers);
97
+ action.init.headers = bus_http_1.ActorHttp.headersToHash(headers);
99
98
  }
100
99
  let requestInit = { ...action.init };
101
100
  if (action.context.get(context_entries_1.KeysHttp.includeCredentials)) {
@@ -105,7 +104,7 @@ class ActorHttpFetch extends bus_http_1.ActorHttp {
105
104
  let requestTimeout;
106
105
  let onTimeout;
107
106
  if (httpTimeout !== undefined) {
108
- const controller = await this.fetchInitPreprocessor.createAbortController();
107
+ const controller = new AbortController();
109
108
  requestInit.signal = controller.signal;
110
109
  onTimeout = () => controller.abort();
111
110
  requestTimeout = setTimeout(() => onTimeout(), httpTimeout);
@@ -122,7 +121,7 @@ class ActorHttpFetch extends bus_http_1.ActorHttp {
122
121
  const response = await ActorHttpFetch.getResponse(customFetch ?? fetch, action.input, requestInit, retryCount, retryDelay, retryOnSeverError);
123
122
  // We remove or update the timeout
124
123
  if (requestTimeout !== undefined) {
125
- const httpBodyTimeout = action.context?.get(context_entries_1.KeysHttp.httpBodyTimeout) || false;
124
+ const httpBodyTimeout = action.context?.get(context_entries_1.KeysHttp.httpBodyTimeout) ?? false;
126
125
  if (httpBodyTimeout && response.body) {
127
126
  // eslint-disable-next-line ts/no-misused-promises
128
127
  onTimeout = () => response.body?.cancel(new Error(`HTTP timeout when reading the body of ${response.url}.
@@ -1 +1 @@
1
- {"version":3,"file":"ActorHttpFetch.js","sourceRoot":"","sources":["ActorHttpFetch.ts"],"names":[],"mappings":";;;AACA,iDAA+C;AAC/C,+DAAqD;AAGrD,gCAA8B;AAC9B,mEAAgE;AAGhE;;;;GAIG;AACH,MAAa,cAAe,SAAQ,oBAAS;IAI3C,YAAmB,IAAyB;QAC1C,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,SAAS,GAAG,cAAc,CAAC,eAAe,EAAE,CAAC;QAClD,IAAI,CAAC,qBAAqB,GAAG,IAAI,6CAAqB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC5E,CAAC;IAEM,MAAM,CAAC,eAAe;QAC3B,OAAO,8BAA8B,OAAO,UAAU,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC;YAChF,WAAW,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnD,WAAW,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC;IACnD,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAAoB;QACpC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC;IAC5C,CAAC;IAED;;;;;;;;OAQG;IACK,MAAM,CAAC,KAAK,CAAC,WAAW,CAC9B,OAAwF,EACxF,YAA+B,EAC/B,WAAwB,EACxB,UAAkB,EAClB,UAAkB,EAClB,kBAA2B;QAE3B,IAAI,SAAkB,CAAC;QACvB,4DAA4D;QAC5D,IAAI,SAAS,GAAG,UA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KAAa,EAAE,EAAE;oBAC5B,QAAQ,CAAC,IAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBAC9C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;wBACjC,4DAA4D;wBAC5D,YAAY,CAAC,cAAc,CAAC,CAAC;oBAC/B,CAAC;gBACH,CAAC,CAAC;YACJ,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;gBACjC,YAAY,CAAC,cAAc,CAAC,CAAC;YAC/B,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA9KD,wCA8KC","sourcesContent":["import type { IActionHttp, IActorHttpOutput, IActorHttpArgs } from '@comunica/bus-http';\nimport { ActorHttp } from '@comunica/bus-http';\nimport { KeysHttp } from '@comunica/context-entries';\nimport type { IMediatorTypeTime } from '@comunica/mediatortype-time';\nimport type { Readable } from 'readable-stream';\nimport 'cross-fetch/polyfill';\nimport { FetchInitPreprocessor } from './FetchInitPreprocessor';\nimport type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';\n\n/**\n * A node-fetch actor that listens on the 'init' bus.\n *\n * It will call `fetch` with either action.input or action.url.\n */\nexport class ActorHttpFetch extends ActorHttp {\n private readonly userAgent: string;\n private readonly fetchInitPreprocessor: IFetchInitPreprocessor;\n\n public constructor(args: IActorHttpFetchArgs) {\n super(args);\n this.userAgent = ActorHttpFetch.createUserAgent();\n this.fetchInitPreprocessor = new FetchInitPreprocessor(args.agentOptions);\n }\n\n public static createUserAgent(): string {\n return `Comunica/actor-http-fetch (${typeof globalThis.navigator === 'undefined' ?\n `Node.js ${process.version}; ${process.platform}` :\n `Browser-${globalThis.navigator.userAgent}`})`;\n }\n\n public async test(_action: IActionHttp): Promise<IMediatorTypeTime> {\n return { time: Number.POSITIVE_INFINITY };\n }\n\n /**\n * Perform a fetch request, taking care of retries\n * @param fetchFn\n * @param requestInput Url or RequestInfo to pass to fetchFn\n * @param requestInit RequestInit to pass to fetch function\n * @param retryCount Maximum retries after which to abort\n * @param retryDelay Time in milliseconds to wait between retries\n * @returns a fetch `Response` object\n */\n private static async getResponse(\n fetchFn: (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>,\n requestInput: RequestInfo | URL,\n requestInit: RequestInit,\n retryCount: number,\n retryDelay: number,\n throwOnServerError: boolean,\n ): Promise<Response> {\n let lastError: unknown;\n // The retryCount is 0-based. Therefore, add 1 to triesLeft.\n let triesLeft = retryCount + 1;\n\n // When retry count is greater than 0, repeat fetch.\n while (triesLeft-- > 0) {\n try {\n const response = await fetchFn(requestInput, requestInit);\n // Check, if server sent a 5xx error response.\n if (throwOnServerError && response.status >= 500 && response.status < 600) {\n throw new Error(`Server replied with response code ${response.status}: ${response.statusText}`);\n }\n return response;\n } catch (error: unknown) {\n lastError = error;\n // If the fetch was aborted by timeout, we won't retry.\n if (requestInit.signal?.aborted) {\n throw error;\n }\n\n if (triesLeft > 0) {\n // Wait for specified delay, before retrying.\n await new Promise((resolve, reject) => {\n setTimeout(resolve, retryDelay);\n // Cancel waiting, if timeout is reached.\n requestInit.signal?.addEventListener('abort', () => {\n reject(new Error('Fetch aborted by timeout.'));\n });\n });\n }\n }\n }\n // The fetch was not successful. We throw.\n if (retryCount > 0) {\n // Feedback the last error, if there were retry attempts.\n throw new Error(`Number of fetch retries (${retryCount}) exceeded. Last error: ${String(lastError)}`);\n } else {\n throw lastError;\n }\n }\n\n public async run(action: IActionHttp): Promise<IActorHttpOutput> {\n // Prepare headers\n const initHeaders = action.init?.headers ?? {};\n action.init = action.init ?? {};\n action.init.headers = new Headers(initHeaders);\n if (!action.init.headers.has('user-agent')) {\n action.init.headers.append('user-agent', this.userAgent);\n }\n const authString: string | undefined = action.context.get(KeysHttp.auth);\n if (authString) {\n action.init.headers.append('Authorization', `Basic ${Buffer.from(authString).toString('base64')}`);\n }\n\n // Log request\n this.logInfo(action.context, `Requesting ${typeof action.input === 'string' ?\n action.input :\n action.input.url}`, () => ({\n headers: ActorHttp.headersToHash(new Headers(action.init!.headers)),\n method: action.init!.method ?? 'GET',\n }));\n\n // TODO: remove this workaround once this has a fix: https://github.com/inrupt/solid-client-authn-js/issues/1708\n if (action.init?.headers && 'append' in action.init.headers && action.context.has(KeysHttp.fetch)) {\n action.init.headers = ActorHttp.headersToHash(action.init.headers);\n }\n\n let requestInit = { ...action.init };\n\n if (action.context.get(KeysHttp.includeCredentials)) {\n requestInit.credentials = 'include';\n }\n\n const httpTimeout: number | undefined = action.context?.get(KeysHttp.httpTimeout);\n let requestTimeout: NodeJS.Timeout | undefined;\n let onTimeout: (() => void) | undefined;\n if (httpTimeout !== undefined) {\n const controller = await this.fetchInitPreprocessor.createAbortController();\n requestInit.signal = controller.signal;\n onTimeout = () => controller.abort();\n requestTimeout = setTimeout(() => onTimeout!(), httpTimeout);\n }\n\n try {\n requestInit = await this.fetchInitPreprocessor.handle(requestInit);\n // Number of retries to perform after a failed fetch.\n const retryCount: number = action.context?.get(KeysHttp.httpRetryCount) ?? 0;\n const retryDelay: number = action.context?.get(KeysHttp.httpRetryDelay) ?? 0;\n const retryOnSeverError: boolean = action.context?.get(KeysHttp.httpRetryOnServerError) ?? false;\n const customFetch: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) | undefined = action\n .context?.get(KeysHttp.fetch);\n\n // Execute the fetch (with retries and timeouts, if applicable).\n const response = await ActorHttpFetch.getResponse(\n customFetch ?? fetch,\n action.input,\n requestInit,\n retryCount,\n retryDelay,\n retryOnSeverError,\n );\n\n // We remove or update the timeout\n if (requestTimeout !== undefined) {\n const httpBodyTimeout = action.context?.get(KeysHttp.httpBodyTimeout) || false;\n if (httpBodyTimeout && response.body) {\n // eslint-disable-next-line ts/no-misused-promises\n onTimeout = () => response.body?.cancel(new Error(`HTTP timeout when reading the body of ${response.url}.\nThis error can be disabled by modifying the 'httpBodyTimeout' and/or 'httpTimeout' options.`));\n (<Readable><any>response.body).on('close', () => {\n clearTimeout(requestTimeout);\n });\n } else {\n clearTimeout(requestTimeout);\n }\n }\n\n // Node-fetch does not support body.cancel, while it is mandatory according to the fetch and readablestream api.\n // If it doesn't exist, we monkey-patch it.\n if (response.body && !response.body.cancel) {\n response.body.cancel = async(error?: Error) => {\n (<Readable><any>response.body).destroy(error);\n if (requestTimeout !== undefined) {\n // We make sure to remove the timeout if it is still enabled\n clearTimeout(requestTimeout);\n }\n };\n }\n\n return response;\n } catch (error: unknown) {\n if (requestTimeout !== undefined) {\n clearTimeout(requestTimeout);\n }\n throw error;\n }\n }\n}\n\nexport interface IActorHttpFetchArgs extends IActorHttpArgs {\n /**\n * The agent options for the HTTP agent\n * @range {json}\n * @default {{ \"keepAlive\": true, \"maxSockets\": 5 }}\n */\n agentOptions?: Record<string, any>;\n}\n"]}
1
+ {"version":3,"file":"ActorHttpFetch.js","sourceRoot":"","sources":["ActorHttpFetch.ts"],"names":[],"mappings":";;;AACA,iDAA+C;AAC/C,+DAAqD;AAErD,yCAA0C;AAG1C,mEAAgE;AAGhE;;;;GAIG;AACH,MAAa,cAAe,SAAQ,oBAAS;IAI3C,YAAmB,IAAyB;QAC1C,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,SAAS,GAAG,cAAc,CAAC,eAAe,EAAE,CAAC;QAClD,IAAI,CAAC,qBAAqB,GAAG,IAAI,6CAAqB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC5E,CAAC;IAEM,MAAM,CAAC,eAAe;QAC3B,OAAO,8BAA8B,OAAO,UAAU,CAAC,SAAS,KAAK,WAAW,CAAC,CAAC;YAChF,WAAW,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnD,WAAW,UAAU,CAAC,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC;IACnD,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAAoB;QACpC,OAAO,IAAA,eAAQ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C;gBAC3C,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,EAAC,KAAa,EAAE,EAAE;oBAC5B,QAAQ,CAAC,IAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBAC9C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;wBACjC,4DAA4D;wBAC5D,YAAY,CAAC,cAAc,CAAC,CAAC;oBAC/B,CAAC;gBACH,CAAC,CAAC;YACJ,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;gBACjC,YAAY,CAAC,cAAc,CAAC,CAAC;YAC/B,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA7KD,wCA6KC","sourcesContent":["import type { IActionHttp, IActorHttpOutput, IActorHttpArgs } from '@comunica/bus-http';\nimport { ActorHttp } from '@comunica/bus-http';\nimport { KeysHttp } from '@comunica/context-entries';\nimport type { TestResult } from '@comunica/core';\nimport { passTest } from '@comunica/core';\nimport type { IMediatorTypeTime } from '@comunica/mediatortype-time';\nimport type { Readable } from 'readable-stream';\nimport { FetchInitPreprocessor } from './FetchInitPreprocessor';\nimport type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';\n\n/**\n * A node-fetch actor that listens on the 'init' bus.\n *\n * It will call `fetch` with either action.input or action.url.\n */\nexport class ActorHttpFetch extends ActorHttp {\n private readonly userAgent: string;\n private readonly fetchInitPreprocessor: IFetchInitPreprocessor;\n\n public constructor(args: IActorHttpFetchArgs) {\n super(args);\n this.userAgent = ActorHttpFetch.createUserAgent();\n this.fetchInitPreprocessor = new FetchInitPreprocessor(args.agentOptions);\n }\n\n public static createUserAgent(): string {\n return `Comunica/actor-http-fetch (${typeof globalThis.navigator === 'undefined' ?\n `Node.js ${process.version}; ${process.platform}` :\n `Browser-${globalThis.navigator.userAgent}`})`;\n }\n\n public async test(_action: IActionHttp): Promise<TestResult<IMediatorTypeTime>> {\n return passTest({ time: Number.POSITIVE_INFINITY });\n }\n\n /**\n * Perform a fetch request, taking care of retries\n * @param fetchFn\n * @param requestInput Url or RequestInfo to pass to fetchFn\n * @param requestInit RequestInit to pass to fetch function\n * @param retryCount Maximum retries after which to abort\n * @param retryDelay Time in milliseconds to wait between retries\n * @returns a fetch `Response` object\n */\n private static async getResponse(\n fetchFn: (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>,\n requestInput: RequestInfo | URL,\n requestInit: RequestInit,\n retryCount: number,\n retryDelay: number,\n throwOnServerError: boolean,\n ): Promise<Response> {\n let lastError: unknown;\n // The retryCount is 0-based. Therefore, add 1 to triesLeft.\n let triesLeft = retryCount + 1;\n\n // When retry count is greater than 0, repeat fetch.\n while (triesLeft-- > 0) {\n try {\n const response = await fetchFn(requestInput, requestInit);\n // Check, if server sent a 5xx error response.\n if (throwOnServerError && response.status >= 500 && response.status < 600) {\n throw new Error(`Server replied with response code ${response.status}: ${response.statusText}`);\n }\n return response;\n } catch (error: unknown) {\n lastError = error;\n // If the fetch was aborted by timeout, we won't retry.\n if (requestInit.signal?.aborted) {\n throw error;\n }\n\n if (triesLeft > 0) {\n // Wait for specified delay, before retrying.\n await new Promise((resolve, reject) => {\n setTimeout(resolve, retryDelay);\n // Cancel waiting, if timeout is reached.\n requestInit.signal?.addEventListener('abort', () => {\n reject(new Error('Fetch aborted by timeout.'));\n });\n });\n }\n }\n }\n // The fetch was not successful. We throw.\n if (retryCount > 0) {\n // Feedback the last error, if there were retry attempts.\n throw new Error(`Number of fetch retries (${retryCount}) exceeded. Last error: ${String(lastError)}`);\n } else {\n throw lastError;\n }\n }\n\n public async run(action: IActionHttp): Promise<IActorHttpOutput> {\n // Prepare headers\n const headers = new Headers(action.init?.headers);\n if (!headers.has('User-Agent')) {\n headers.set('User-Agent', this.userAgent);\n }\n const authString = action.context.get<string>(KeysHttp.auth);\n if (authString) {\n headers.set('Authorization', `Basic ${Buffer.from(authString).toString('base64')}`);\n }\n action.init = { ...action.init, headers };\n\n // Log request\n this.logInfo(action.context, `Requesting ${typeof action.input === 'string' ?\n action.input :\n action.input.url}`, () => ({\n headers: ActorHttp.headersToHash(headers),\n method: action.init!.method ?? 'GET',\n }));\n\n // TODO: remove this workaround once this has a fix: https://github.com/inrupt/solid-client-authn-js/issues/1708\n if (action.init?.headers && 'append' in action.init.headers && action.context.has(KeysHttp.fetch)) {\n action.init.headers = ActorHttp.headersToHash(headers);\n }\n\n let requestInit: RequestInit = { ...action.init };\n\n if (action.context.get(KeysHttp.includeCredentials)) {\n requestInit.credentials = 'include';\n }\n\n const httpTimeout: number | undefined = action.context?.get(KeysHttp.httpTimeout);\n let requestTimeout: NodeJS.Timeout | undefined;\n let onTimeout: (() => void) | undefined;\n if (httpTimeout !== undefined) {\n const controller = new AbortController();\n requestInit.signal = controller.signal;\n onTimeout = () => controller.abort();\n requestTimeout = setTimeout(() => onTimeout!(), httpTimeout);\n }\n\n try {\n requestInit = await this.fetchInitPreprocessor.handle(requestInit);\n // Number of retries to perform after a failed fetch.\n const retryCount: number = action.context?.get(KeysHttp.httpRetryCount) ?? 0;\n const retryDelay: number = action.context?.get(KeysHttp.httpRetryDelay) ?? 0;\n const retryOnSeverError: boolean = action.context?.get(KeysHttp.httpRetryOnServerError) ?? false;\n const customFetch: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) | undefined = action\n .context?.get(KeysHttp.fetch);\n\n // Execute the fetch (with retries and timeouts, if applicable).\n const response = await ActorHttpFetch.getResponse(\n customFetch ?? fetch,\n action.input,\n requestInit,\n retryCount,\n retryDelay,\n retryOnSeverError,\n );\n\n // We remove or update the timeout\n if (requestTimeout !== undefined) {\n const httpBodyTimeout = action.context?.get(KeysHttp.httpBodyTimeout) ?? false;\n if (httpBodyTimeout && response.body) {\n // eslint-disable-next-line ts/no-misused-promises\n onTimeout = () => response.body?.cancel(new Error(`HTTP timeout when reading the body of ${response.url}.\nThis error can be disabled by modifying the 'httpBodyTimeout' and/or 'httpTimeout' options.`));\n (<Readable><any>response.body).on('close', () => {\n clearTimeout(requestTimeout);\n });\n } else {\n clearTimeout(requestTimeout);\n }\n }\n\n // Node-fetch does not support body.cancel, while it is mandatory according to the fetch and readablestream api.\n // If it doesn't exist, we monkey-patch it.\n if (response.body && !response.body.cancel) {\n response.body.cancel = async(error?: Error) => {\n (<Readable><any>response.body).destroy(error);\n if (requestTimeout !== undefined) {\n // We make sure to remove the timeout if it is still enabled\n clearTimeout(requestTimeout);\n }\n };\n }\n\n return response;\n } catch (error: unknown) {\n if (requestTimeout !== undefined) {\n clearTimeout(requestTimeout);\n }\n throw error;\n }\n }\n}\n\nexport interface IActorHttpFetchArgs extends IActorHttpArgs {\n /**\n * The agent options for the HTTP agent\n * @range {json}\n * @default {{ \"keepAlive\": true, \"maxSockets\": 5 }}\n */\n agentOptions?: Record<string, any>;\n}\n"]}
@@ -4,5 +4,4 @@ import type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';
4
4
  */
5
5
  export declare class FetchInitPreprocessor implements IFetchInitPreprocessor {
6
6
  handle(init: RequestInit): Promise<RequestInit>;
7
- createAbortController(): Promise<AbortController>;
8
7
  }
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable unicorn/filename-case */
3
- /* eslint-enable unicorn/filename-case */
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
3
  exports.FetchInitPreprocessor = void 0;
6
4
  const bus_http_1 = require("@comunica/bus-http");
@@ -41,9 +39,6 @@ class FetchInitPreprocessor {
41
39
  // Only enable keepalive functionality if we are not sending a body (some browsers seem to trip over this)
42
40
  return { keepalive: !init.body, ...init };
43
41
  }
44
- async createAbortController() {
45
- return new AbortController();
46
- }
47
42
  }
48
43
  exports.FetchInitPreprocessor = FetchInitPreprocessor;
49
44
  //# sourceMappingURL=FetchInitPreprocessor-browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FetchInitPreprocessor-browser.js","sourceRoot":"","sources":["Fetch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C,EAAE,CAAC,CAAC;QAC9B,CAAC;QAED,0GAA0G;QAC1G,OAAO,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;IAC5C,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAChC,OAAO,IAAI,eAAe,EAAE,CAAC;IAC/B,CAAC;CACF;AA1CD,sDA0CC","sourcesContent":["/* eslint-disable unicorn/filename-case */\n/* eslint-enable unicorn/filename-case */\n\nimport { ActorHttp } from '@comunica/bus-http';\nimport type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';\n\n/**\n * Overrides things for fetch requests in browsers\n */\nexport class FetchInitPreprocessor implements IFetchInitPreprocessor {\n public async handle(init: RequestInit): Promise<RequestInit> {\n // Remove overridden user-agent header within browsers to avoid CORS issues\n if (init.headers) {\n const headers = new Headers(init.headers);\n if (headers.has('user-agent')) {\n headers.delete('user-agent');\n }\n init.headers = headers;\n }\n\n // TODO: remove this workaround once this has a fix: https://github.com/inrupt/solid-client-authn-js/issues/1708\n if (init?.headers && 'append' in init.headers) {\n init.headers = ActorHttp.headersToHash(init.headers);\n }\n\n // Browsers don't yet support passing ReadableStream as body to requests, see\n // https://bugs.chromium.org/p/chromium/issues/detail?id=688906\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1387483\n // As such, we convert those bodies to a plain string\n // TODO: remove this once browser support ReadableStream in requests\n if (init.body && typeof init.body !== 'string' && 'getReader' in init.body) {\n const reader = init.body.getReader();\n const chunks = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n chunks.push(value);\n }\n init.body = chunks.join('');\n }\n\n // Only enable keepalive functionality if we are not sending a body (some browsers seem to trip over this)\n return { keepalive: !init.body, ...init };\n }\n\n public async createAbortController(): Promise<AbortController> {\n return new AbortController();\n }\n}\n"]}
1
+ {"version":3,"file":"FetchInitPreprocessor-browser.js","sourceRoot":"","sources":["FetchInitPreprocessor-browser.ts"],"names":[],"mappings":";;;AAAA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,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;IAC5C,CAAC;CACF;AAtCD,sDAsCC","sourcesContent":["import { ActorHttp } from '@comunica/bus-http';\nimport type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';\n\n/**\n * Overrides things for fetch requests in browsers\n */\nexport class FetchInitPreprocessor implements IFetchInitPreprocessor {\n public async handle(init: RequestInit): Promise<RequestInit> {\n // Remove overridden user-agent header within browsers to avoid CORS issues\n if (init.headers) {\n const headers = new Headers(init.headers);\n if (headers.has('user-agent')) {\n headers.delete('user-agent');\n }\n init.headers = headers;\n }\n\n // TODO: remove this workaround once this has a fix: https://github.com/inrupt/solid-client-authn-js/issues/1708\n if (init?.headers && 'append' in init.headers) {\n init.headers = ActorHttp.headersToHash(init.headers);\n }\n\n // Browsers don't yet support passing ReadableStream as body to requests, see\n // https://bugs.chromium.org/p/chromium/issues/detail?id=688906\n // https://bugzilla.mozilla.org/show_bug.cgi?id=1387483\n // As such, we convert those bodies to a plain string\n // TODO: remove this once browser support ReadableStream in requests\n if (init.body && typeof init.body !== 'string' && 'getReader' in init.body) {\n const reader = init.body.getReader();\n const chunks = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n chunks.push(value);\n }\n init.body = chunks.join('');\n }\n\n // Only enable keepalive functionality if we are not sending a body (some browsers seem to trip over this)\n return { keepalive: !init.body, ...init };\n }\n}\n"]}
@@ -6,5 +6,4 @@ export declare class FetchInitPreprocessor implements IFetchInitPreprocessor {
6
6
  private readonly agent;
7
7
  constructor(agentOptions: any);
8
8
  handle(init: RequestInit): Promise<RequestInit>;
9
- createAbortController(): Promise<AbortController>;
10
9
  }
@@ -24,6 +24,12 @@ class FetchInitPreprocessor {
24
24
  // - 'duplex' must be set to 'half'
25
25
  halfDuplex = true;
26
26
  }
27
+ // Add 'Accept-Encoding' headers
28
+ const headers = new Headers(init.headers);
29
+ if (!headers.has('Accept-Encoding')) {
30
+ headers.set('Accept-Encoding', 'br,gzip,deflate');
31
+ init = { ...init, headers };
32
+ }
27
33
  return {
28
34
  ...init,
29
35
  agent: this.agent,
@@ -31,12 +37,6 @@ class FetchInitPreprocessor {
31
37
  duplex: halfDuplex ? 'half' : undefined,
32
38
  };
33
39
  }
34
- async createAbortController() {
35
- // Fallback to abort-controller for Node 14 backward compatibility
36
- /* istanbul ignore next */
37
- const AbortController = globalThis.AbortController || await Promise.resolve().then(() => require('abort-controller'));
38
- return new AbortController();
39
- }
40
40
  }
41
41
  exports.FetchInitPreprocessor = FetchInitPreprocessor;
42
42
  /* eslint-enable import/no-nodejs-modules */
@@ -1 +1 @@
1
- {"version":3,"file":"FetchInitPreprocessor.js","sourceRoot":"","sources":["FetchInitPreprocessor.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,yCAA+C;AAC/C,2CAAiD;AACjD,iDAA+C;AAG/C;;GAEG;AACH,MAAa,qBAAqB;IAGhC,YAAmB,YAAiB;QAClC,MAAM,SAAS,GAAG,IAAI,iBAAS,CAAC,YAAY,CAAC,CAAC;QAC9C,MAAM,UAAU,GAAG,IAAI,kBAAU,CAAC,YAAY,CAAC,CAAC;QAChD,IAAI,CAAC,KAAK,GAAG,CAAC,UAAe,EAAa,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;IACxG,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,IAAiB;QACnC,qFAAqF;QACrF,IAAI,UAAU,GAAG,KAAK,CAAC;QACvB,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,WAAW,IAAU,IAAI,CAAC,IAAI,EAAE,CAAC;YACjF,IAAI,CAAC,IAAI,GAAS,oBAAS,CAAC,cAAc,CAAO,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5D,+EAA+E;YAC/E,gCAAgC;YAChC,mCAAmC;YACnC,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;QAED,OAAa;YACX,GAAG,IAAI;YACP,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;YACxC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SACxC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAChC,kEAAkE;QAClE,0BAA0B;QAC1B,MAAM,eAAe,GAAG,UAAU,CAAC,eAAe,IAAI,2CAAa,kBAAkB,EAAC,CAAC;QACvF,OAAO,IAAI,eAAe,EAAE,CAAC;IAC/B,CAAC;CACF;AAlCD,sDAkCC;AACD,4CAA4C","sourcesContent":["/* eslint-disable import/no-nodejs-modules */\nimport { Agent as HttpAgent } from 'node:http';\nimport { Agent as HttpsAgent } from 'node:https';\nimport { ActorHttp } from '@comunica/bus-http';\nimport type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';\n\n/**\n * Overrides the HTTP agent to perform better in Node.js.\n */\nexport class FetchInitPreprocessor implements IFetchInitPreprocessor {\n private readonly agent: (url: URL) => HttpAgent;\n\n public constructor(agentOptions: any) {\n const httpAgent = new HttpAgent(agentOptions);\n const httpsAgent = new HttpsAgent(agentOptions);\n this.agent = (_parsedURL: URL): HttpAgent => _parsedURL.protocol === 'http:' ? httpAgent : httpsAgent;\n }\n\n public async handle(init: RequestInit): Promise<RequestInit> {\n // Convert body Web stream to Node stream, as node-fetch does not support Web streams\n let halfDuplex = false;\n if (init.body && typeof init.body !== 'string' && 'getReader' in <any> init.body) {\n init.body = <any> ActorHttp.toNodeReadable(<any> init.body);\n // The Fetch API requires specific options to be set when sending body streams:\n // - 'keepalive' can not be true\n // - 'duplex' must be set to 'half'\n halfDuplex = true;\n }\n\n return <any> {\n ...init,\n agent: this.agent,\n keepalive: halfDuplex ? undefined : true,\n duplex: halfDuplex ? 'half' : undefined,\n };\n }\n\n public async createAbortController(): Promise<AbortController> {\n // Fallback to abort-controller for Node 14 backward compatibility\n /* istanbul ignore next */\n const AbortController = globalThis.AbortController || await import('abort-controller');\n return new AbortController();\n }\n}\n/* eslint-enable import/no-nodejs-modules */\n"]}
1
+ {"version":3,"file":"FetchInitPreprocessor.js","sourceRoot":"","sources":["FetchInitPreprocessor.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,yCAA+C;AAC/C,2CAAiD;AACjD,iDAA+C;AAG/C;;GAEG;AACH,MAAa,qBAAqB;IAGhC,YAAmB,YAAiB;QAClC,MAAM,SAAS,GAAG,IAAI,iBAAS,CAAC,YAAY,CAAC,CAAC;QAC9C,MAAM,UAAU,GAAG,IAAI,kBAAU,CAAC,YAAY,CAAC,CAAC;QAChD,IAAI,CAAC,KAAK,GAAG,CAAC,UAAe,EAAa,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;IACxG,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,IAAiB;QACnC,qFAAqF;QACrF,IAAI,UAAU,GAAG,KAAK,CAAC;QACvB,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,WAAW,IAAU,IAAI,CAAC,IAAI,EAAE,CAAC;YACjF,IAAI,CAAC,IAAI,GAAS,oBAAS,CAAC,cAAc,CAAO,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5D,+EAA+E;YAC/E,gCAAgC;YAChC,mCAAmC;YACnC,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;QAED,gCAAgC;QAChC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACpC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;YAClD,IAAI,GAAG,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC;QAC9B,CAAC;QAED,OAAa;YACX,GAAG,IAAI;YACP,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;YACxC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SACxC,CAAC;IACJ,CAAC;CACF;AAlCD,sDAkCC;AACD,4CAA4C","sourcesContent":["/* eslint-disable import/no-nodejs-modules */\nimport { Agent as HttpAgent } from 'node:http';\nimport { Agent as HttpsAgent } from 'node:https';\nimport { ActorHttp } from '@comunica/bus-http';\nimport type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';\n\n/**\n * Overrides the HTTP agent to perform better in Node.js.\n */\nexport class FetchInitPreprocessor implements IFetchInitPreprocessor {\n private readonly agent: (url: URL) => HttpAgent;\n\n public constructor(agentOptions: any) {\n const httpAgent = new HttpAgent(agentOptions);\n const httpsAgent = new HttpsAgent(agentOptions);\n this.agent = (_parsedURL: URL): HttpAgent => _parsedURL.protocol === 'http:' ? httpAgent : httpsAgent;\n }\n\n public async handle(init: RequestInit): Promise<RequestInit> {\n // Convert body Web stream to Node stream, as node-fetch does not support Web streams\n let halfDuplex = false;\n if (init.body && typeof init.body !== 'string' && 'getReader' in <any> init.body) {\n init.body = <any> ActorHttp.toNodeReadable(<any> init.body);\n // The Fetch API requires specific options to be set when sending body streams:\n // - 'keepalive' can not be true\n // - 'duplex' must be set to 'half'\n halfDuplex = true;\n }\n\n // Add 'Accept-Encoding' headers\n const headers = new Headers(init.headers);\n if (!headers.has('Accept-Encoding')) {\n headers.set('Accept-Encoding', 'br,gzip,deflate');\n init = { ...init, headers };\n }\n\n return <any> {\n ...init,\n agent: this.agent,\n keepalive: halfDuplex ? undefined : true,\n duplex: halfDuplex ? 'half' : undefined,\n };\n }\n}\n/* eslint-enable import/no-nodejs-modules */\n"]}
@@ -3,5 +3,4 @@
3
3
  */
4
4
  export interface IFetchInitPreprocessor {
5
5
  handle: (init: RequestInit) => Promise<RequestInit>;
6
- createAbortController: () => Promise<AbortController>;
7
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IFetchInitPreprocessor.js","sourceRoot":"","sources":["IFetchInitPreprocessor.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Can modify a fetch init object.\n */\nexport interface IFetchInitPreprocessor {\n handle: (init: RequestInit) => Promise<RequestInit>;\n createAbortController: () => Promise<AbortController>;\n}\n"]}
1
+ {"version":3,"file":"IFetchInitPreprocessor.js","sourceRoot":"","sources":["IFetchInitPreprocessor.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Can modify a fetch init object.\n */\nexport interface IFetchInitPreprocessor {\n handle: (init: RequestInit) => Promise<RequestInit>;\n}\n"]}
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@comunica/actor-http-fetch",
3
- "version": "3.3.0",
3
+ "version": "4.0.1-alpha.48.0",
4
4
  "description": "A node-fetch http actor",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
7
+ "funding": {
8
+ "type": "opencollective",
9
+ "url": "https://opencollective.com/comunica-association"
10
+ },
7
11
  "homepage": "https://comunica.dev/",
8
12
  "repository": {
9
13
  "type": "git",
@@ -35,14 +39,13 @@
35
39
  "build:components": "componentsjs-generator"
36
40
  },
37
41
  "dependencies": {
38
- "@comunica/bus-http": "^3.3.0",
39
- "@comunica/context-entries": "^3.3.0",
40
- "@comunica/mediatortype-time": "^3.3.0",
41
- "abort-controller": "^3.0.0",
42
- "cross-fetch": "^4.0.0"
42
+ "@comunica/bus-http": "4.0.1-alpha.48.0",
43
+ "@comunica/context-entries": "4.0.1-alpha.48.0",
44
+ "@comunica/core": "4.0.1-alpha.48.0",
45
+ "@comunica/mediatortype-time": "4.0.1-alpha.48.0"
43
46
  },
44
47
  "browser": {
45
48
  "./lib/FetchInitPreprocessor.js": "./lib/FetchInitPreprocessor-browser.js"
46
49
  },
47
- "gitHead": "02bde397d206f1f5a523643a6a604c89e792e2f9"
50
+ "gitHead": "4cc37905eab2c94a2e1d9cee0f51c53604f07da1"
48
51
  }