@comunica/actor-http-fetch 2.8.2 → 2.10.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.
@@ -16,10 +16,20 @@ class FetchInitPreprocessor {
16
16
  }
17
17
  async handle(init) {
18
18
  // Convert body Web stream to Node stream, as node-fetch does not support Web streams
19
+ let halfDuplex = false;
19
20
  if (init.body && typeof init.body !== 'string' && 'getReader' in init.body) {
20
21
  init.body = bus_http_1.ActorHttp.toNodeReadable(init.body);
22
+ // The Fetch API requires specific options to be set when sending body streams:
23
+ // - 'keepalive' can not be true
24
+ // - 'duplex' must be set to 'half'
25
+ halfDuplex = true;
21
26
  }
22
- return { ...init, agent: this.agent, keepalive: true };
27
+ return {
28
+ ...init,
29
+ agent: this.agent,
30
+ keepalive: !halfDuplex ? true : undefined,
31
+ duplex: halfDuplex ? 'half' : undefined,
32
+ };
23
33
  }
24
34
  async createAbortController() {
25
35
  // Fallback to abort-controller for Node 14 backward compatibility
@@ -1 +1 @@
1
- {"version":3,"file":"FetchInitPreprocessor.js","sourceRoot":"","sources":["FetchInitPreprocessor.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,+BAA0C;AAC1C,iCAA4C;AAC5C,iDAA+C;AAG/C;;GAEG;AACH,MAAa,qBAAqB;IAGhC,YAAmB,YAAiB;QAClC,MAAM,SAAS,GAAG,IAAI,YAAS,CAAC,YAAY,CAAC,CAAC;QAC9C,MAAM,UAAU,GAAG,IAAI,aAAU,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,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,WAAW,IAAU,IAAI,CAAC,IAAI,EAAE;YAChF,IAAI,CAAC,IAAI,GAAS,oBAAS,CAAC,cAAc,CAAO,IAAI,CAAC,IAAI,CAAC,CAAC;SAC7D;QAED,OAAa,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAC/D,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;AAxBD,sDAwBC;AACD,4CAA4C","sourcesContent":["/* eslint-disable import/no-nodejs-modules */\nimport { Agent as HttpAgent } from 'http';\nimport { Agent as HttpsAgent } from '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 if (init.body && typeof init.body !== 'string' && 'getReader' in <any> init.body) {\n init.body = <any> ActorHttp.toNodeReadable(<any> init.body);\n }\n\n return <any> { ...init, agent: this.agent, keepalive: true };\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"]}
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IAAI,eAAe,EAAE,CAAC;IAC/B,CAAC;CACF;AAlCD,sDAkCC;AACD,4CAA4C","sourcesContent":["/* eslint-disable import/no-nodejs-modules */\nimport { Agent as HttpAgent } from 'http';\nimport { Agent as HttpsAgent } from '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 ? true : undefined,\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comunica/actor-http-fetch",
3
- "version": "2.8.2",
3
+ "version": "2.10.1",
4
4
  "description": "A node-fetch http actor",
5
5
  "lsd:module": true,
6
6
  "main": "lib/index.js",
@@ -30,9 +30,9 @@
30
30
  "lib/**/*.js.map"
31
31
  ],
32
32
  "dependencies": {
33
- "@comunica/bus-http": "^2.8.2",
34
- "@comunica/context-entries": "^2.8.2",
35
- "@comunica/mediatortype-time": "^2.8.2",
33
+ "@comunica/bus-http": "^2.10.0",
34
+ "@comunica/context-entries": "^2.10.0",
35
+ "@comunica/mediatortype-time": "^2.10.0",
36
36
  "abort-controller": "^3.0.0",
37
37
  "cross-fetch": "^4.0.0"
38
38
  },
@@ -44,5 +44,5 @@
44
44
  "browser": {
45
45
  "./lib/FetchInitPreprocessor.js": "./lib/FetchInitPreprocessor-browser.js"
46
46
  },
47
- "gitHead": "293cf4edac83099ee3146a68161bea6b77edf300"
47
+ "gitHead": "4d0383bd0f7cef463daf7044e9add498f8c67797"
48
48
  }