@comunica/actor-http-fetch 2.0.1-alpha.5.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/LICENSE.txt +22 -0
- package/README.md +43 -0
- package/components/ActorHttpFetch.jsonld +196 -0
- package/components/components.jsonld +11 -0
- package/components/context.jsonld +46 -0
- package/lib/ActorHttpFetch.d.ts +25 -0
- package/lib/ActorHttpFetch.js +67 -0
- package/lib/FetchInitPreprocessor-browser.d.ts +7 -0
- package/lib/FetchInitPreprocessor-browser.js +21 -0
- package/lib/FetchInitPreprocessor.d.ts +9 -0
- package/lib/FetchInitPreprocessor.js +25 -0
- package/lib/IFetchInitPreprocessor.d.ts +6 -0
- package/lib/IFetchInitPreprocessor.js +3 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +14 -0
- package/package.json +46 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2017–now Ruben Taelman, Joachim Van Herwegen
|
|
4
|
+
Comunica Association and Ghent University – imec, Belgium
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Comunica Fetch HTTP Actor
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@comunica/actor-http-fetch)
|
|
4
|
+
|
|
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.
|
|
7
|
+
|
|
8
|
+
This module is part of the [Comunica framework](https://github.com/comunica/comunica),
|
|
9
|
+
and should only be used by [developers that want to build their own query engine](https://comunica.dev/docs/modify/).
|
|
10
|
+
|
|
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
|
+
|
|
14
|
+
[Click here if you just want to query with Comunica](https://comunica.dev/docs/query/).
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
$ yarn add @comunica/actor-http-fetch
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Configure
|
|
23
|
+
|
|
24
|
+
After installing, this package can be added to your engine's configuration as follows:
|
|
25
|
+
```text
|
|
26
|
+
{
|
|
27
|
+
"@context": [
|
|
28
|
+
...
|
|
29
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^2.0.0/components/context.jsonld"
|
|
30
|
+
],
|
|
31
|
+
"actors": [
|
|
32
|
+
...
|
|
33
|
+
{
|
|
34
|
+
"@id": "urn:comunica:default:http/actors#fetch",
|
|
35
|
+
"@type": "ActorHttpFetch"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Config Parameters
|
|
42
|
+
|
|
43
|
+
* `agentOptions`: The agent JSON options for the HTTP agent. _(optional)_
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^2.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-http/^2.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^2.0.0/components/context.jsonld"
|
|
6
|
+
],
|
|
7
|
+
"@id": "npmd:@comunica/actor-http-fetch",
|
|
8
|
+
"components": [
|
|
9
|
+
{
|
|
10
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch",
|
|
11
|
+
"@type": "Class",
|
|
12
|
+
"requireElement": "ActorHttpFetch",
|
|
13
|
+
"extends": [
|
|
14
|
+
"cbh:components/ActorHttp.jsonld#ActorHttp"
|
|
15
|
+
],
|
|
16
|
+
"comment": "A node-fetch actor that listens on the 'init' bus. It will call `fetch` with either action.input or action.url.",
|
|
17
|
+
"parameters": [
|
|
18
|
+
{
|
|
19
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_agentOptions",
|
|
20
|
+
"range": {
|
|
21
|
+
"@type": "ParameterRangeUnion",
|
|
22
|
+
"parameterRangeElements": [
|
|
23
|
+
"rdf:JSON",
|
|
24
|
+
{
|
|
25
|
+
"@type": "ParameterRangeUndefined"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"default": {
|
|
30
|
+
"@type": "@json",
|
|
31
|
+
"@value": {
|
|
32
|
+
"keepAlive": true,
|
|
33
|
+
"maxSockets": 5
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"comment": "The agent options for the HTTP agent"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_name",
|
|
40
|
+
"range": "xsd:string",
|
|
41
|
+
"default": {
|
|
42
|
+
"@id": "rdf:subject"
|
|
43
|
+
},
|
|
44
|
+
"comment": "The name for this actor."
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_bus",
|
|
48
|
+
"range": {
|
|
49
|
+
"@type": "ParameterRangeGenericComponent",
|
|
50
|
+
"component": "cc:components/Bus.jsonld#Bus",
|
|
51
|
+
"genericTypeInstances": [
|
|
52
|
+
{
|
|
53
|
+
"@type": "ParameterRangeGenericComponent",
|
|
54
|
+
"component": "cc:components/Actor.jsonld#Actor",
|
|
55
|
+
"genericTypeInstances": [
|
|
56
|
+
{
|
|
57
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
58
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
62
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
66
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
72
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
76
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
80
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
"default": {
|
|
85
|
+
"@id": "cbh:components/ActorHttp.jsonld#ActorHttp_default_bus",
|
|
86
|
+
"@type": "cc:components/Bus.jsonld#Bus"
|
|
87
|
+
},
|
|
88
|
+
"comment": "The bus this actor subscribes to."
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_beforeActors",
|
|
92
|
+
"range": {
|
|
93
|
+
"@type": "ParameterRangeUnion",
|
|
94
|
+
"parameterRangeElements": [
|
|
95
|
+
{
|
|
96
|
+
"@type": "ParameterRangeArray",
|
|
97
|
+
"parameterRangeValue": {
|
|
98
|
+
"@type": "ParameterRangeGenericComponent",
|
|
99
|
+
"component": "cc:components/Actor.jsonld#Actor",
|
|
100
|
+
"genericTypeInstances": [
|
|
101
|
+
{
|
|
102
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
103
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
107
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
111
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^2.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"@type": "ParameterRangeUndefined"
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
"comment": "Actor that must be registered in the bus before this actor."
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
"memberFields": [
|
|
125
|
+
{
|
|
126
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch__member_userAgent",
|
|
127
|
+
"memberFieldName": "userAgent"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch__member_fetchInitPreprocessor",
|
|
131
|
+
"memberFieldName": "fetchInitPreprocessor"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch__member_constructor",
|
|
135
|
+
"memberFieldName": "constructor"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch__member_createUserAgent",
|
|
139
|
+
"memberFieldName": "createUserAgent"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch__member_test",
|
|
143
|
+
"memberFieldName": "test"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch__member_run",
|
|
147
|
+
"memberFieldName": "run"
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
"constructorArguments": [
|
|
151
|
+
{
|
|
152
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args__constructorArgument",
|
|
153
|
+
"fields": [
|
|
154
|
+
{
|
|
155
|
+
"keyRaw": "agentOptions",
|
|
156
|
+
"value": {
|
|
157
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_agentOptions"
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"keyRaw": "name",
|
|
162
|
+
"value": {
|
|
163
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_name"
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"keyRaw": "bus",
|
|
168
|
+
"value": {
|
|
169
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_bus"
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"keyRaw": "beforeActors",
|
|
174
|
+
"value": {
|
|
175
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_beforeActors"
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#IActorHttpFetchArgs",
|
|
184
|
+
"@type": "AbstractClass",
|
|
185
|
+
"requireElement": "IActorHttpFetchArgs",
|
|
186
|
+
"parameters": [],
|
|
187
|
+
"memberFields": [
|
|
188
|
+
{
|
|
189
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#IActorHttpFetchArgs__member_agentOptions",
|
|
190
|
+
"memberFieldName": "agentOptions"
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
"constructorArguments": []
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-fetch/^2.0.0/components/context.jsonld"
|
|
4
|
+
],
|
|
5
|
+
"@id": "npmd:@comunica/actor-http-fetch",
|
|
6
|
+
"@type": "Module",
|
|
7
|
+
"requireName": "@comunica/actor-http-fetch",
|
|
8
|
+
"import": [
|
|
9
|
+
"cahf:components/ActorHttpFetch.jsonld"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^4.0.0/components/context.jsonld",
|
|
4
|
+
{
|
|
5
|
+
"npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
|
|
6
|
+
"cahf": "npmd:@comunica/actor-http-fetch/^2.0.0/",
|
|
7
|
+
"ActorHttpFetch": {
|
|
8
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch",
|
|
9
|
+
"@prefix": true,
|
|
10
|
+
"@context": {
|
|
11
|
+
"args_agentOptions": {
|
|
12
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_agentOptions"
|
|
13
|
+
},
|
|
14
|
+
"args_name": {
|
|
15
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_name"
|
|
16
|
+
},
|
|
17
|
+
"args_bus": {
|
|
18
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_bus"
|
|
19
|
+
},
|
|
20
|
+
"args_beforeActors": {
|
|
21
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_beforeActors",
|
|
22
|
+
"@container": "@list"
|
|
23
|
+
},
|
|
24
|
+
"agentOptions": {
|
|
25
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_agentOptions"
|
|
26
|
+
},
|
|
27
|
+
"name": {
|
|
28
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_name"
|
|
29
|
+
},
|
|
30
|
+
"bus": {
|
|
31
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_bus"
|
|
32
|
+
},
|
|
33
|
+
"beforeActors": {
|
|
34
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#ActorHttpFetch_args_beforeActors",
|
|
35
|
+
"@container": "@list"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"IActorHttpFetchArgs": {
|
|
40
|
+
"@id": "cahf:components/ActorHttpFetch.jsonld#IActorHttpFetchArgs",
|
|
41
|
+
"@prefix": true,
|
|
42
|
+
"@context": {}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IActionHttp, IActorHttpOutput, IActorHttpArgs } from '@comunica/bus-http';
|
|
2
|
+
import { ActorHttp } from '@comunica/bus-http';
|
|
3
|
+
import type { IMediatorTypeTime } from '@comunica/mediatortype-time';
|
|
4
|
+
import 'cross-fetch/polyfill';
|
|
5
|
+
/**
|
|
6
|
+
* A node-fetch actor that listens on the 'init' bus.
|
|
7
|
+
*
|
|
8
|
+
* It will call `fetch` with either action.input or action.url.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ActorHttpFetch extends ActorHttp {
|
|
11
|
+
private readonly userAgent;
|
|
12
|
+
private readonly fetchInitPreprocessor;
|
|
13
|
+
constructor(args: IActorHttpFetchArgs);
|
|
14
|
+
static createUserAgent(): string;
|
|
15
|
+
test(action: IActionHttp): Promise<IMediatorTypeTime>;
|
|
16
|
+
run(action: IActionHttp): Promise<IActorHttpOutput>;
|
|
17
|
+
}
|
|
18
|
+
export interface IActorHttpFetchArgs extends IActorHttpArgs {
|
|
19
|
+
/**
|
|
20
|
+
* The agent options for the HTTP agent
|
|
21
|
+
* @range {json}
|
|
22
|
+
* @default {{ "keepAlive": true, "maxSockets": 5 }}
|
|
23
|
+
*/
|
|
24
|
+
agentOptions?: Record<string, any>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActorHttpFetch = void 0;
|
|
4
|
+
const bus_http_1 = require("@comunica/bus-http");
|
|
5
|
+
const context_entries_1 = require("@comunica/context-entries");
|
|
6
|
+
require("cross-fetch/polyfill");
|
|
7
|
+
const FetchInitPreprocessor_1 = require("./FetchInitPreprocessor");
|
|
8
|
+
/**
|
|
9
|
+
* A node-fetch actor that listens on the 'init' bus.
|
|
10
|
+
*
|
|
11
|
+
* It will call `fetch` with either action.input or action.url.
|
|
12
|
+
*/
|
|
13
|
+
class ActorHttpFetch extends bus_http_1.ActorHttp {
|
|
14
|
+
constructor(args) {
|
|
15
|
+
super(args);
|
|
16
|
+
this.userAgent = ActorHttpFetch.createUserAgent();
|
|
17
|
+
this.fetchInitPreprocessor = new FetchInitPreprocessor_1.FetchInitPreprocessor(args.agentOptions);
|
|
18
|
+
}
|
|
19
|
+
static createUserAgent() {
|
|
20
|
+
return `Comunica/actor-http-fetch (${typeof global.navigator === 'undefined' ?
|
|
21
|
+
`Node.js ${process.version}; ${process.platform}` :
|
|
22
|
+
`Browser-${global.navigator.userAgent}`})`;
|
|
23
|
+
}
|
|
24
|
+
async test(action) {
|
|
25
|
+
return { time: Number.POSITIVE_INFINITY };
|
|
26
|
+
}
|
|
27
|
+
run(action) {
|
|
28
|
+
// Prepare headers
|
|
29
|
+
const initHeaders = action.init ? action.init.headers || {} : {};
|
|
30
|
+
action.init = action.init ? action.init : {};
|
|
31
|
+
action.init.headers = new Headers(initHeaders);
|
|
32
|
+
if (!action.init.headers.has('user-agent')) {
|
|
33
|
+
action.init.headers.append('user-agent', this.userAgent);
|
|
34
|
+
}
|
|
35
|
+
const authString = action.context.get(context_entries_1.KeysHttp.auth);
|
|
36
|
+
if (authString) {
|
|
37
|
+
action.init.headers.append('Authorization', `Basic ${Buffer.from(authString).toString('base64')}`);
|
|
38
|
+
}
|
|
39
|
+
// Log request
|
|
40
|
+
this.logInfo(action.context, `Requesting ${typeof action.input === 'string' ?
|
|
41
|
+
action.input :
|
|
42
|
+
action.input.url}`, () => ({
|
|
43
|
+
headers: bus_http_1.ActorHttp.headersToHash(new Headers(action.init.headers)),
|
|
44
|
+
method: action.init.method || 'GET',
|
|
45
|
+
}));
|
|
46
|
+
// TODO: remove this workaround once this has a fix: https://github.com/inrupt/solid-client-authn-js/issues/1708
|
|
47
|
+
if (action.init && action.init.headers && 'append' in action.init.headers && action.context.has(context_entries_1.KeysHttp.fetch)) {
|
|
48
|
+
action.init.headers = bus_http_1.ActorHttp.headersToHash(action.init.headers);
|
|
49
|
+
}
|
|
50
|
+
// Perform request
|
|
51
|
+
const customFetch = action
|
|
52
|
+
.context?.get(context_entries_1.KeysHttp.fetch);
|
|
53
|
+
return (customFetch || fetch)(action.input, this.fetchInitPreprocessor.handle({
|
|
54
|
+
...action.init,
|
|
55
|
+
...action.context && action.context.get(context_entries_1.KeysHttp.includeCredentials) ? { credentials: 'include' } : {},
|
|
56
|
+
})).then(response => {
|
|
57
|
+
// Node-fetch does not support body.cancel, while it is mandatory according to the fetch and readablestream api.
|
|
58
|
+
// If it doesn't exist, we monkey-patch it.
|
|
59
|
+
if (response.body && !response.body.cancel) {
|
|
60
|
+
response.body.cancel = async (error) => response.body.destroy(error);
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.ActorHttpFetch = ActorHttpFetch;
|
|
67
|
+
//# sourceMappingURL=ActorHttpFetch.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchInitPreprocessor = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Does nothing in browsers
|
|
6
|
+
*/
|
|
7
|
+
class FetchInitPreprocessor {
|
|
8
|
+
handle(init) {
|
|
9
|
+
// Remove overridden user-agent header within browsers to avoid CORS issues
|
|
10
|
+
if (init.headers) {
|
|
11
|
+
const headers = new Headers(init.headers);
|
|
12
|
+
if (headers.has('user-agent')) {
|
|
13
|
+
headers.delete('user-agent');
|
|
14
|
+
}
|
|
15
|
+
init.headers = headers;
|
|
16
|
+
}
|
|
17
|
+
return { keepalive: true, ...init };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.FetchInitPreprocessor = FetchInitPreprocessor;
|
|
21
|
+
//# sourceMappingURL=FetchInitPreprocessor-browser.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IFetchInitPreprocessor } from './IFetchInitPreprocessor';
|
|
2
|
+
/**
|
|
3
|
+
* Overrides the HTTP agent to perform better in Node.js.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FetchInitPreprocessor implements IFetchInitPreprocessor {
|
|
6
|
+
private readonly agent;
|
|
7
|
+
constructor(agentOptions: any);
|
|
8
|
+
handle(init: RequestInit): RequestInit;
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchInitPreprocessor = void 0;
|
|
4
|
+
const http_1 = require("http");
|
|
5
|
+
const https_1 = require("https");
|
|
6
|
+
const bus_http_1 = require("@comunica/bus-http");
|
|
7
|
+
/**
|
|
8
|
+
* Overrides the HTTP agent to perform better in Node.js.
|
|
9
|
+
*/
|
|
10
|
+
class FetchInitPreprocessor {
|
|
11
|
+
constructor(agentOptions) {
|
|
12
|
+
const httpAgent = new http_1.Agent(agentOptions);
|
|
13
|
+
const httpsAgent = new https_1.Agent(agentOptions);
|
|
14
|
+
this.agent = (_parsedURL) => _parsedURL.protocol === 'http:' ? httpAgent : httpsAgent;
|
|
15
|
+
}
|
|
16
|
+
handle(init) {
|
|
17
|
+
// Convert body Web stream to Node stream, as node-fetch does not support Web streams
|
|
18
|
+
if (init.body && 'getReader' in init.body) {
|
|
19
|
+
init.body = bus_http_1.ActorHttp.toNodeReadable(init.body);
|
|
20
|
+
}
|
|
21
|
+
return { ...init, agent: this.agent };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.FetchInitPreprocessor = FetchInitPreprocessor;
|
|
25
|
+
//# sourceMappingURL=FetchInitPreprocessor.js.map
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ActorHttpFetch';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./ActorHttpFetch"), exports);
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@comunica/actor-http-fetch",
|
|
3
|
+
"version": "2.0.1-alpha.5.0",
|
|
4
|
+
"description": "A node-fetch http actor",
|
|
5
|
+
"lsd:module": true,
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"typings": "lib/index",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/comunica/comunica.git",
|
|
11
|
+
"directory": "packages/actor-http-fetch"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"comunica",
|
|
18
|
+
"runner"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/comunica/comunica/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://comunica.dev/",
|
|
25
|
+
"files": [
|
|
26
|
+
"components",
|
|
27
|
+
"lib/**/*.d.ts",
|
|
28
|
+
"lib/**/*.js"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@comunica/bus-http": "2.0.1-alpha.5.0",
|
|
32
|
+
"@comunica/context-entries": "2.0.1-alpha.5.0",
|
|
33
|
+
"@comunica/core": "2.0.1-alpha.5.0",
|
|
34
|
+
"@comunica/mediatortype-time": "2.0.1-alpha.5.0",
|
|
35
|
+
"cross-fetch": "^3.0.5"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "npm run build:ts && npm run build:components",
|
|
39
|
+
"build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
|
|
40
|
+
"build:components": "componentsjs-generator"
|
|
41
|
+
},
|
|
42
|
+
"browser": {
|
|
43
|
+
"./lib/FetchInitPreprocessor.js": "./lib/FetchInitPreprocessor-browser.js"
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "e2ae2e9e924bf0656df60cc99774f7e560d47695"
|
|
46
|
+
}
|