@comunica/actor-http-native 4.5.0 → 5.0.2
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 +1 -1
- package/components/ActorHttpNative.jsonld +15 -15
- package/components/components.jsonld +1 -1
- package/components/context.jsonld +1 -1
- package/lib/ActorHttpNative.d.ts +0 -0
- package/lib/ActorHttpNative.js +2 -1
- package/lib/ActorHttpNative.js.map +1 -1
- package/lib/Requester-browser.d.ts +0 -2
- package/lib/Requester-browser.js +2 -0
- package/lib/Requester-browser.js.map +1 -1
- package/lib/Requester.d.ts +0 -2
- package/lib/Requester.js +1 -0
- package/lib/Requester.js.map +1 -1
- package/lib/index.d.ts +0 -0
- package/lib/index.js +0 -0
- package/lib/index.js.map +0 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ After installing, this package can be added to your engine's configuration as fo
|
|
|
25
25
|
{
|
|
26
26
|
"@context": [
|
|
27
27
|
...
|
|
28
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-native/^
|
|
28
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-native/^5.0.0/components/context.jsonld"
|
|
29
29
|
],
|
|
30
30
|
"actors": [
|
|
31
31
|
...
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-native/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-http/^
|
|
5
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-native/^5.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-http/^5.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^5.0.0/components/context.jsonld"
|
|
6
6
|
],
|
|
7
7
|
"@id": "npmd:@comunica/actor-http-native",
|
|
8
8
|
"components": [
|
|
@@ -55,37 +55,37 @@
|
|
|
55
55
|
"genericTypeInstances": [
|
|
56
56
|
{
|
|
57
57
|
"@type": "ParameterRangeGenericTypeReference",
|
|
58
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
58
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
"@type": "ParameterRangeGenericTypeReference",
|
|
62
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
62
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
65
|
"@type": "ParameterRangeGenericTypeReference",
|
|
66
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
66
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
69
|
"@type": "ParameterRangeGenericTypeReference",
|
|
70
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
70
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
71
71
|
}
|
|
72
72
|
]
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
"@type": "ParameterRangeGenericTypeReference",
|
|
76
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
76
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
79
|
"@type": "ParameterRangeGenericTypeReference",
|
|
80
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
80
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
83
|
"@type": "ParameterRangeGenericTypeReference",
|
|
84
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
84
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
"@type": "ParameterRangeGenericTypeReference",
|
|
88
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
88
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
89
89
|
}
|
|
90
90
|
]
|
|
91
91
|
},
|
|
@@ -122,19 +122,19 @@
|
|
|
122
122
|
"genericTypeInstances": [
|
|
123
123
|
{
|
|
124
124
|
"@type": "ParameterRangeGenericTypeReference",
|
|
125
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
125
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
128
|
"@type": "ParameterRangeGenericTypeReference",
|
|
129
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
129
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
130
130
|
},
|
|
131
131
|
{
|
|
132
132
|
"@type": "ParameterRangeGenericTypeReference",
|
|
133
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
133
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
136
|
"@type": "ParameterRangeGenericTypeReference",
|
|
137
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
137
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
138
138
|
}
|
|
139
139
|
]
|
|
140
140
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-native/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-http-native/^5.0.0/components/context.jsonld"
|
|
4
4
|
],
|
|
5
5
|
"@id": "npmd:@comunica/actor-http-native",
|
|
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
|
-
"cahn": "npmd:@comunica/actor-http-native/^
|
|
6
|
+
"cahn": "npmd:@comunica/actor-http-native/^5.0.0/",
|
|
7
7
|
"ActorHttpNative": {
|
|
8
8
|
"@id": "cahn:components/ActorHttpNative.jsonld#ActorHttpNative",
|
|
9
9
|
"@prefix": true,
|
package/lib/ActorHttpNative.d.ts
CHANGED
|
File without changes
|
package/lib/ActorHttpNative.js
CHANGED
|
@@ -11,6 +11,8 @@ const Requester_1 = require("./Requester");
|
|
|
11
11
|
* A comunica Follow Redirects Http Actor.
|
|
12
12
|
*/
|
|
13
13
|
class ActorHttpNative extends bus_http_1.ActorHttp {
|
|
14
|
+
static userAgent = bus_http_1.ActorHttp.createUserAgent('ActorHttpNative', package_json_1.version);
|
|
15
|
+
requester;
|
|
14
16
|
constructor(args) {
|
|
15
17
|
super(args);
|
|
16
18
|
this.requester = new Requester_1.default(args.agentOptions);
|
|
@@ -106,5 +108,4 @@ class ActorHttpNative extends bus_http_1.ActorHttp {
|
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
exports.ActorHttpNative = ActorHttpNative;
|
|
109
|
-
ActorHttpNative.userAgent = bus_http_1.ActorHttp.createUserAgent('ActorHttpNative', package_json_1.version);
|
|
110
111
|
//# sourceMappingURL=ActorHttpNative.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorHttpNative.js","sourceRoot":"","sources":["ActorHttpNative.ts"],"names":[],"mappings":";;;AACA,iDAA+C;AAC/C,+DAAqD;AAErD,yCAA0C;AAG1C,6CAA6C;AAC7C,kDAA0D;AAE1D,2CAAoC;AAEpC;;GAEG;AACH,MAAa,eAAgB,SAAQ,oBAAS;
|
|
1
|
+
{"version":3,"file":"ActorHttpNative.js","sourceRoot":"","sources":["ActorHttpNative.ts"],"names":[],"mappings":";;;AACA,iDAA+C;AAC/C,+DAAqD;AAErD,yCAA0C;AAG1C,6CAA6C;AAC7C,kDAA0D;AAE1D,2CAAoC;AAEpC;;GAEG;AACH,MAAa,eAAgB,SAAQ,oBAAS;IACpC,MAAM,CAAU,SAAS,GAAG,oBAAS,CAAC,eAAe,CAAC,iBAAiB,EAAE,sBAAY,CAAC,CAAC;IAE9E,SAAS,CAAY;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,WAAW;yBAClG,CAAC;wBACF,OAAO,CAAC,MAAM,CAAC,CAAC;oBAClB,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;;AA1GH,0CA2GC","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';\n\n// eslint-disable-next-line import/extensions\nimport { version as actorVersion } from '../package.json';\n\nimport Requester from './Requester';\n\n/**\n * A comunica Follow Redirects Http Actor.\n */\nexport class ActorHttpNative extends ActorHttp {\n private static readonly userAgent = ActorHttp.createUserAgent('ActorHttpNative', actorVersion);\n\n private readonly requester: Requester;\n\n public constructor(args: IActorHttpNativeArgs) {\n super(args);\n this.requester = new Requester(args.agentOptions);\n }\n\n public async test(_action: IActionHttp): Promise<TestResult<IMediatorTypeTime>> {\n return passTest({ time: Number.POSITIVE_INFINITY });\n }\n\n public async run(action: IActionHttp): Promise<IActorHttpOutput> {\n const options: any = {};\n // Input can be a Request object or a string\n // if it is a Request object it can contain the same settings as the init object\n if ((<any>action.input).url) {\n options.url = (<Request>action.input).url;\n Object.assign(options, action.input);\n } else {\n options.url = action.input;\n }\n\n if (action.init) {\n Object.assign(options, action.init);\n options.headers = new Headers(action.init.headers);\n options.body = action.init.body;\n } else {\n options.headers = (<Request>action.input).headers;\n if ((<Request>action.input).body) {\n throw new Error(`ActorHttpNative does not support passing body via input, use init instead.`);\n }\n }\n\n if (!options.headers) {\n options.headers = new Headers();\n }\n if (!options.headers.has('user-agent')) {\n options.headers.append('user-agent', ActorHttpNative.userAgent);\n }\n\n options.method = options.method || 'GET';\n if (action.context.get(KeysHttp.includeCredentials)) {\n options.withCredentials = true;\n }\n\n if (action.context.get(KeysHttp.auth)) {\n options.auth = action.context.get(KeysHttp.auth);\n }\n\n this.logInfo(action.context, `Requesting ${options.url}`, () => ({\n headers: ActorHttp.headersToHash(options.headers),\n method: options.method,\n }));\n\n // Not all options are supported\n\n return new Promise<IActorHttpOutput>((resolve, reject) => {\n const req = this.requester.createRequest(options);\n req.on('error', reject);\n req.on('response', (httpResponse) => {\n httpResponse.on('error', (error: Error) => {\n httpResponse = null;\n reject(error);\n });\n // Avoid memory leak on HEAD requests\n if (options.method === 'HEAD') {\n httpResponse.destroy();\n }\n // Using setImmediate so error can be caught should it be thrown\n setTimeout(() => {\n if (httpResponse) {\n // Expose fetch cancel promise\n httpResponse.cancel = () => {\n httpResponse.destroy();\n return Promise.resolve();\n };\n\n // Support abort controller\n if (action.init?.signal) {\n if (action.init.signal.aborted) {\n httpResponse.destroy();\n } else {\n action.init.signal.addEventListener('abort', () => httpResponse.destroy());\n }\n }\n\n // Missing several of the required fetch fields\n const headers = httpResponse.headers;\n\n const result = <IActorHttpOutput> {\n body: httpResponse,\n headers,\n ok: httpResponse.statusCode < 300,\n redirected: options.url !== httpResponse.responseUrl,\n status: httpResponse.statusCode,\n // When the content came from another resource because of conneg, let Content-Location deliver the url\n url: headers.has('content-location') ? headers.get('content-location') : httpResponse.responseUrl,\n };\n resolve(result);\n }\n });\n });\n });\n }\n}\n\nexport interface IActorHttpNativeArgs 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"]}
|
package/lib/Requester-browser.js
CHANGED
|
@@ -9,6 +9,8 @@ const http_link_header_1 = require("http-link-header");
|
|
|
9
9
|
// Headers we cannot send (see https://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader()-method)
|
|
10
10
|
const UNSAFE_REQUEST_HEADERS = { 'accept-encoding': true, 'user-agent': true, referer: true };
|
|
11
11
|
class Requester {
|
|
12
|
+
// Resources that were already time-negotiated
|
|
13
|
+
negotiatedResources;
|
|
12
14
|
constructor() {
|
|
13
15
|
this.negotiatedResources = {};
|
|
14
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Requester-browser.js","sourceRoot":"","sources":["Requester-browser.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,yDAAyD;AACzD,yGAAyG;;AAEzG,6CAA2C;AAE3C,6CAAuC;AACvC,uDAAyC;AAEzC,mGAAmG;AACnG,MAAM,sBAAsB,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAE9F,MAAqB,SAAS;
|
|
1
|
+
{"version":3,"file":"Requester-browser.js","sourceRoot":"","sources":["Requester-browser.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,yDAAyD;AACzD,yGAAyG;;AAEzG,6CAA2C;AAE3C,6CAAuC;AACvC,uDAAyC;AAEzC,mGAAmG;AACnG,MAAM,sBAAsB,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAE9F,MAAqB,SAAS;IAC5B,8CAA8C;IACtC,mBAAmB,CAA0B;IAErD;QACE,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;IAED,kDAAkD;IAC3C,aAAa,CAAC,QAAa;QAChC,oBAAoB;QACpB,2EAA2E;QAC3E,2EAA2E;QAC3E,IAAI,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAClD,QAAQ,CAAC,OAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACzD,CAAC;QAED,mCAAmC;QACnC,MAAM,OAAO,GAAG,IAAI,cAAc,EAAE,CAAC;QACrC,MAAM,UAAU,GAAY,QAAQ,CAAC,OAAO,CAAC;QAC7C,OAAO,CAAC,IAA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AC,MAAM,CAAC,GAAG,EAAW,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,sCAAsC;IAC9B,WAAW,CAAC,GAAY;QAC9B,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;CACF;AAlHD,4BAkHC","sourcesContent":["/* ! @license MIT ©2013-2016 Ruben Verborgh, Ghent University - imec */\n/* Single-function HTTP(S) request module for browsers */\n/* Translated from https://github.com/LinkedDataFragments/Client.js/blob/master/lib/browser/Request.js */\n\nimport { EventEmitter } from 'node:events';\nimport type { IncomingHttpHeaders, IncomingMessage } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { parse } from 'http-link-header';\n\n// Headers we cannot send (see https://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader()-method)\nconst UNSAFE_REQUEST_HEADERS = { 'accept-encoding': true, 'user-agent': true, referer: true };\n\nexport default class Requester {\n // Resources that were already time-negotiated\n private negotiatedResources: Record<string, boolean>;\n\n public constructor() {\n this.negotiatedResources = {};\n }\n\n // Creates an HTTP request with the given settings\n public createRequest(settings: any): EventEmitter {\n // PERFORMANCE HACK:\n // Reduce OPTIONS preflight requests by removing the Accept-Datetime header\n // on requests for resources that are presumed to have been time-negotiated\n if (this.negotiatedResources[this.removeQuery(settings.url)]) {\n (<Headers> settings.headers).delete('accept-datetime');\n }\n\n // Create the actual XMLHttpRequest\n const request = new XMLHttpRequest();\n const reqHeaders: Headers = settings.headers;\n request.open(settings.method, settings.url, true);\n request.timeout = settings.timeout;\n request.withCredentials = settings.withCredentials;\n\n // eslint-disable-next-line unicorn/no-array-for-each\n reqHeaders.forEach((value, key) => {\n if (!(key in UNSAFE_REQUEST_HEADERS) && value) {\n request.setRequestHeader(key, value);\n }\n });\n\n // Create a proxy for the XMLHttpRequest\n const requestProxy = new EventEmitter();\n (<any> requestProxy).abort = () => {\n request.abort();\n };\n\n // Handle the arrival of a response\n request.onload = () => {\n // Convert the response into an iterator\n const response: IncomingMessage = <IncomingMessage> new Readable();\n response.push(request.responseText || '');\n response.push(null);\n response.statusCode = request.status;\n (<any> response).responseUrl = request.responseURL;\n\n // Parse the response headers\n const resHeaders: Headers = this.convertRequestHeadersToFetchHeaders(response.headers);\n response.headers = <any> resHeaders;\n const rawHeaders = request.getAllResponseHeaders() || '';\n const headerMatcher = /^([^\\n\\r:]+):[\\t ]*([^\\n\\r]*)$/gmu;\n let match = headerMatcher.exec(rawHeaders);\n while (match) {\n resHeaders.set(match[1].toLowerCase(), match[2]);\n match = headerMatcher.exec(rawHeaders);\n }\n\n // Emit the response\n requestProxy.emit('response', response);\n\n // If the resource was time-negotiated, store its queryless URI\n // to enable the PERFORMANCE HACK explained above\n if (reqHeaders.has('accept-datetime') && resHeaders.has('memento-datetime')) {\n const resource = this.removeQuery(resHeaders.get('content-location') ?? settings.url);\n if (!this.negotiatedResources[resource]) {\n // Ensure the resource is not a timegate\n const header = resHeaders.get('link');\n const tg = header && parse(header)?.get('rel', 'timegate');\n const timegate = this.removeQuery(tg && tg.length > 0 ? tg[0].uri : undefined);\n if (resource !== timegate) {\n this.negotiatedResources[resource] = true;\n }\n }\n }\n };\n // Report errors and timeouts\n request.onerror = () => {\n requestProxy.emit('error', new Error(`Error requesting ${settings.url}`));\n };\n request.ontimeout = () => {\n requestProxy.emit('error', new Error(`Timeout requesting ${settings.url}`));\n };\n\n // Execute the request\n if (settings.body) {\n if (settings.body instanceof URLSearchParams) {\n request.send(settings.body.toString());\n } else if (typeof settings.body === 'string') {\n request.send(settings.body);\n } else {\n settings.body.blob()\n .then((blob: any) => request.send(blob))\n .catch((error: Error) => requestProxy.emit('error', error));\n }\n } else {\n request.send();\n }\n\n return requestProxy;\n }\n\n // Wrap headers into an header object type\n public convertRequestHeadersToFetchHeaders(headers: IncomingHttpHeaders): Headers {\n const responseHeaders: Headers = new Headers();\n for (const key in headers) {\n responseHeaders.append(key, <string> headers[key]);\n }\n return responseHeaders;\n }\n\n // Removes the query string from a URL\n private removeQuery(url?: string): string {\n return url ? url.replace(/\\?.*$/u, '') : '';\n }\n}\n"]}
|
package/lib/Requester.d.ts
CHANGED
package/lib/Requester.js
CHANGED
|
@@ -12,6 +12,7 @@ const { https } = require('follow-redirects');
|
|
|
12
12
|
// Decode encoded streams with these decoders
|
|
13
13
|
const DECODERS = { gzip: zlib.createGunzip, deflate: zlib.createInflate };
|
|
14
14
|
class Requester {
|
|
15
|
+
agents;
|
|
15
16
|
constructor(agentOptions) {
|
|
16
17
|
this.agents = {
|
|
17
18
|
http: new http.Agent(agentOptions ?? {}),
|
package/lib/Requester.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Requester.js","sourceRoot":"","sources":["Requester.ts"],"names":[],"mappings":";AAAA,kEAAkE;AAClE,4CAA4C;AAC5C,sGAAsG;;AAEtG,6CAA2C;AAE3C,gCAAgC;AAChC,kCAAkC;AAClC,iDAA+C;AAE/C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC7C,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAE9C,6CAA6C;AAC7C,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC;AAE1E,MAAqB,SAAS;
|
|
1
|
+
{"version":3,"file":"Requester.js","sourceRoot":"","sources":["Requester.ts"],"names":[],"mappings":";AAAA,kEAAkE;AAClE,4CAA4C;AAC5C,sGAAsG;;AAEtG,6CAA2C;AAE3C,gCAAgC;AAChC,kCAAkC;AAClC,iDAA+C;AAE/C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC7C,MAAM,EAAE,KAAK,EA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,OAAO,EAAE,CAAC;YAC1B,eAAe,CAAC,MAAM,CAAC,GAAG,EAAW,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,uDAAuD;IAC/C,MAAM,CAAC,QAAyB;QACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACtD,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBACzB,oBAAoB;gBACpB,MAAM,OAAO,GAAU,QAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACvB,2BAA2B;gBAC3B,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;gBACzC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,mCAAmC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBAC7E,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,uCAAuC;YACvC,UAAU,CAAC,GAAG,EAAE;gBACd,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC,CAAC;YACzE,CAAC,CAAC,CAAC;QACL,CAAC;QAED,QAAQ,CAAC,OAAO,GAAS,IAAI,CAAC,mCAAmC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAxFD,4BAwFC","sourcesContent":["/* ! @license MIT ©2016 Ruben Verborgh, Ghent University - imec */\n/* Single-function HTTP(S) request module */\n/* Translated from https://github.com/LinkedDataFragments/Client.js/blob/master/lib/util/Request.js */\n\nimport { EventEmitter } from 'node:events';\nimport type { AgentOptions, ClientRequest, IncomingMessage, IncomingHttpHeaders } from 'node:http';\nimport * as url from 'node:url';\nimport * as zlib from 'node:zlib';\nimport { ActorHttp } from '@comunica/bus-http';\n\nconst { http } = require('follow-redirects');\nconst { https } = require('follow-redirects');\n\n// Decode encoded streams with these decoders\nconst DECODERS = { gzip: zlib.createGunzip, deflate: zlib.createInflate };\n\nexport default class Requester {\n private readonly agents: any;\n\n public constructor(agentOptions?: AgentOptions) {\n this.agents = {\n http: new http.Agent(agentOptions ?? {}),\n https: new https.Agent(agentOptions ?? {}),\n };\n }\n\n // Creates an HTTP request with the given settings\n public createRequest(settings: any): EventEmitter {\n // Parse the request URL\n if (settings.url) {\n // eslint-disable-next-line node/no-deprecated-api\n settings = { ...url.parse(settings.url), ...settings };\n }\n\n // Emit the response through a proxy\n const requestProxy = new EventEmitter();\n const requester = settings.protocol === 'http:' ? http : https;\n settings.agents = this.agents;\n\n // Unpacking headers object into a plain object\n const headersObject: any = {};\n if (settings.headers) {\n // eslint-disable-next-line unicorn/no-array-for-each\n (<Headers> settings.headers).forEach((value, key) => {\n headersObject[key] = value;\n });\n }\n settings.headers = headersObject;\n const request: ClientRequest = requester.request(settings, (response: IncomingMessage) => {\n response = this.decode(response);\n settings.headers = response.headers;\n response.setEncoding('utf8');\n // This was removed compared to the original LDF client implementation\n // response.pause(); // exit flow mode\n requestProxy.emit('response', response);\n });\n request.on('error', error => requestProxy.emit('error', error));\n if (settings.body) {\n if (settings.body instanceof URLSearchParams) {\n request.write(settings.body.toString());\n request.end();\n } else if (typeof settings.body === 'string') {\n request.write(settings.body);\n request.end();\n } else {\n ActorHttp.toNodeReadable(settings.body).pipe(request);\n }\n } else {\n request.end();\n }\n return requestProxy;\n }\n\n // Wrap headers into an header object type\n public convertRequestHeadersToFetchHeaders(headers: IncomingHttpHeaders): Headers {\n const responseHeaders: Headers = new Headers();\n for (const key in headers) {\n responseHeaders.append(key, <string> headers[key]);\n }\n return responseHeaders;\n }\n\n // Returns a decompressed stream from the HTTP response\n private decode(response: IncomingMessage): IncomingMessage {\n const encoding = response.headers['content-encoding'];\n if (encoding) {\n if (encoding in DECODERS) {\n // Decode the stream\n const decoded = (<any> DECODERS)[encoding]();\n response.pipe(decoded);\n // Copy response properties\n decoded.statusCode = response.statusCode;\n decoded.headers = this.convertRequestHeadersToFetchHeaders(response.headers);\n return decoded;\n }\n // Error when no suitable decoder found\n setTimeout(() => {\n response.emit('error', new Error(`Unsupported encoding: ${encoding}`));\n });\n }\n\n response.headers = <any> this.convertRequestHeadersToFetchHeaders(response.headers);\n return response;\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
File without changes
|
package/lib/index.js
CHANGED
|
File without changes
|
package/lib/index.js.map
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-http-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "A native http actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"build:components": "componentsjs-generator"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@comunica/bus-http": "^
|
|
45
|
-
"@comunica/context-entries": "^
|
|
46
|
-
"@comunica/core": "^
|
|
47
|
-
"@comunica/mediatortype-time": "^
|
|
44
|
+
"@comunica/bus-http": "^5.0.2",
|
|
45
|
+
"@comunica/context-entries": "^5.0.2",
|
|
46
|
+
"@comunica/core": "^5.0.2",
|
|
47
|
+
"@comunica/mediatortype-time": "^5.0.2",
|
|
48
48
|
"@types/http-link-header": "^1.0.7",
|
|
49
49
|
"follow-redirects": "^1.15.2",
|
|
50
50
|
"http-link-header": "^1.1.3"
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"browser": {
|
|
53
53
|
"./lib/Requester.js": "./lib/Requester-browser.js"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "3b29f914010fd2fc56682a0ceff962ef6ff24f32"
|
|
56
56
|
}
|