fix(core): update
This commit is contained in:
parent
59c0c4e60c
commit
73c10c1db8
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/webrequest',
|
name: '@pushrocks/webrequest',
|
||||||
version: '3.0.11',
|
version: '3.0.12',
|
||||||
description: 'securely request from browsers'
|
description: 'securely request from browsers'
|
||||||
}
|
}
|
||||||
|
27
ts/index.ts
27
ts/index.ts
@ -12,7 +12,8 @@ export class WebRequest {
|
|||||||
private static neededPolyfillsLoadedDeferred = plugins.smartpromise.defer<{
|
private static neededPolyfillsLoadedDeferred = plugins.smartpromise.defer<{
|
||||||
fetch: typeof fetch,
|
fetch: typeof fetch,
|
||||||
Response: typeof Response,
|
Response: typeof Response,
|
||||||
AbortController: typeof AbortController
|
AbortController?: typeof AbortController,
|
||||||
|
helixTimeout?: any,
|
||||||
}>();
|
}>();
|
||||||
public static async loadNeededPolyfills() {
|
public static async loadNeededPolyfills() {
|
||||||
if (this.polyfillStatusEvaluated) {
|
if (this.polyfillStatusEvaluated) {
|
||||||
@ -26,7 +27,7 @@ export class WebRequest {
|
|||||||
this.neededPolyfillsLoadedDeferred.resolve({
|
this.neededPolyfillsLoadedDeferred.resolve({
|
||||||
fetch: fetchMod.fetch,
|
fetch: fetchMod.fetch,
|
||||||
Response: fetchMod.Response,
|
Response: fetchMod.Response,
|
||||||
AbortController: fetchMod.AbortSignal
|
helixTimeout: fetchMod.timeoutSignal,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.neededPolyfillsLoadedDeferred.resolve({
|
this.neededPolyfillsLoadedDeferred.resolve({
|
||||||
@ -115,12 +116,24 @@ export class WebRequest {
|
|||||||
timeoutMs?: number;
|
timeoutMs?: number;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
|
optionsArg = {
|
||||||
|
timeoutMs: 60000,
|
||||||
|
useCache: false,
|
||||||
|
...optionsArg,
|
||||||
|
}
|
||||||
const fetchObject = await WebRequest.neededPolyfillsLoadedDeferred.promise;
|
const fetchObject = await WebRequest.neededPolyfillsLoadedDeferred.promise;
|
||||||
const controller = new fetchObject.AbortController();
|
let controller: AbortController;
|
||||||
if (optionsArg.timeoutMs) {
|
if (optionsArg.timeoutMs) {
|
||||||
plugins.smartdelay.delayFor(optionsArg.timeoutMs).then(() => {
|
if (fetchObject.AbortController) {
|
||||||
controller.abort();
|
controller = new fetchObject.AbortController();
|
||||||
});
|
plugins.smartdelay.delayFor(optionsArg.timeoutMs).then(() => {
|
||||||
|
controller.abort();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
controller = {
|
||||||
|
signal: fetchObject.helixTimeout(optionsArg.timeoutMs)
|
||||||
|
} as any;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let cachedResponseDeferred = plugins.smartpromise.defer<Response>();
|
let cachedResponseDeferred = plugins.smartpromise.defer<Response>();
|
||||||
let cacheUsed = false;
|
let cacheUsed = false;
|
||||||
@ -131,7 +144,7 @@ export class WebRequest {
|
|||||||
cachedResponseDeferred.resolve(null);
|
cachedResponseDeferred.resolve(null);
|
||||||
}
|
}
|
||||||
let response: Response = await fetchObject.fetch(urlArg, {
|
let response: Response = await fetchObject.fetch(urlArg, {
|
||||||
signal: controller.signal,
|
signal: controller ? controller.signal : null,
|
||||||
method: optionsArg.method,
|
method: optionsArg.method,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
Loading…
Reference in New Issue
Block a user