@comunica/actor-http-fetch 2.2.0 → 2.2.1
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/lib/ActorHttpFetch.js +2 -2
- package/lib/FetchInitPreprocessor-browser.d.ts +2 -2
- package/lib/FetchInitPreprocessor-browser.js +20 -2
- package/lib/FetchInitPreprocessor.d.ts +1 -1
- package/lib/FetchInitPreprocessor.js +1 -1
- package/lib/IFetchInitPreprocessor.d.ts +1 -1
- package/package.json +2 -2
package/lib/ActorHttpFetch.js
CHANGED
|
@@ -24,7 +24,7 @@ class ActorHttpFetch extends bus_http_1.ActorHttp {
|
|
|
24
24
|
async test(action) {
|
|
25
25
|
return { time: Number.POSITIVE_INFINITY };
|
|
26
26
|
}
|
|
27
|
-
run(action) {
|
|
27
|
+
async run(action) {
|
|
28
28
|
// Prepare headers
|
|
29
29
|
const initHeaders = action.init ? action.init.headers || {} : {};
|
|
30
30
|
action.init = action.init ? action.init : {};
|
|
@@ -50,7 +50,7 @@ class ActorHttpFetch extends bus_http_1.ActorHttp {
|
|
|
50
50
|
// Perform request
|
|
51
51
|
const customFetch = action
|
|
52
52
|
.context?.get(context_entries_1.KeysHttp.fetch);
|
|
53
|
-
return (customFetch || fetch)(action.input, this.fetchInitPreprocessor.handle({
|
|
53
|
+
return await (customFetch || fetch)(action.input, await this.fetchInitPreprocessor.handle({
|
|
54
54
|
...action.init,
|
|
55
55
|
...action.context.get(context_entries_1.KeysHttp.includeCredentials) ? { credentials: 'include' } : {},
|
|
56
56
|
})).then(response => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Overrides things for fetch requests in browsers
|
|
4
4
|
*/
|
|
5
5
|
export declare class FetchInitPreprocessor implements IFetchInitPreprocessor {
|
|
6
|
-
handle(init: RequestInit): RequestInit
|
|
6
|
+
handle(init: RequestInit): Promise<RequestInit>;
|
|
7
7
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FetchInitPreprocessor = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Overrides things for fetch requests in browsers
|
|
6
6
|
*/
|
|
7
7
|
class FetchInitPreprocessor {
|
|
8
|
-
handle(init) {
|
|
8
|
+
async handle(init) {
|
|
9
9
|
// Remove overridden user-agent header within browsers to avoid CORS issues
|
|
10
10
|
if (init.headers) {
|
|
11
11
|
const headers = new Headers(init.headers);
|
|
@@ -14,6 +14,24 @@ class FetchInitPreprocessor {
|
|
|
14
14
|
}
|
|
15
15
|
init.headers = headers;
|
|
16
16
|
}
|
|
17
|
+
// Browsers don't yet support passing ReadableStream as body to requests, see
|
|
18
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=688906
|
|
19
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1387483
|
|
20
|
+
// As such, we convert those bodies to a plain string
|
|
21
|
+
// TODO: remove this once browser support ReadableStream in requests
|
|
22
|
+
if (init.body && typeof init.body !== 'string' && 'getReader' in init.body) {
|
|
23
|
+
const reader = init.body.getReader();
|
|
24
|
+
const chunks = [];
|
|
25
|
+
// eslint-disable-next-line no-constant-condition
|
|
26
|
+
while (true) {
|
|
27
|
+
const { done, value } = await reader.read();
|
|
28
|
+
if (done) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
chunks.push(value);
|
|
32
|
+
}
|
|
33
|
+
init.body = chunks.join('');
|
|
34
|
+
}
|
|
17
35
|
// Only enable keepalive functionality if we are not sending a body (some browsers seem to trip over this)
|
|
18
36
|
return { keepalive: !init.body, ...init };
|
|
19
37
|
}
|
|
@@ -5,5 +5,5 @@ import type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';
|
|
|
5
5
|
export declare class FetchInitPreprocessor implements IFetchInitPreprocessor {
|
|
6
6
|
private readonly agent;
|
|
7
7
|
constructor(agentOptions: any);
|
|
8
|
-
handle(init: RequestInit): RequestInit
|
|
8
|
+
handle(init: RequestInit): Promise<RequestInit>;
|
|
9
9
|
}
|
|
@@ -13,7 +13,7 @@ class FetchInitPreprocessor {
|
|
|
13
13
|
const httpsAgent = new https_1.Agent(agentOptions);
|
|
14
14
|
this.agent = (_parsedURL) => _parsedURL.protocol === 'http:' ? httpAgent : httpsAgent;
|
|
15
15
|
}
|
|
16
|
-
handle(init) {
|
|
16
|
+
async handle(init) {
|
|
17
17
|
// Convert body Web stream to Node stream, as node-fetch does not support Web streams
|
|
18
18
|
if (init.body && typeof init.body !== 'string' && 'getReader' in init.body) {
|
|
19
19
|
init.body = bus_http_1.ActorHttp.toNodeReadable(init.body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-http-fetch",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "A node-fetch http actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"browser": {
|
|
44
44
|
"./lib/FetchInitPreprocessor.js": "./lib/FetchInitPreprocessor-browser.js"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "b2a0bee9640e2bcf70492fd7c497bab3d0e14113"
|
|
47
47
|
}
|