Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _addURLToCache({cacheKey, url, cacheMode, event, plugins, integrity}: {
cacheKey: string,
url: string,
cacheMode: "reload" | "default" | "no-store" | "no-cache" | "force-cache" | "only-if-cached" | undefined,
event?: ExtendableEvent,
plugins?: WorkboxPlugin[],
integrity?: string,
}) {
const request = new Request(url, {
integrity,
cache: cacheMode,
credentials: 'same-origin',
});
let response = await fetchWrapper.fetch({
event,
plugins,
request,
});
// Allow developers to override the default logic about what is and isn't
// valid by passing in a plugin implementing cacheWillUpdate(), e.g.
// a workbox.cacheableResponse.CacheableResponsePlugin instance.
let cacheWillUpdatePlugin;
for (const plugin of (plugins || [])) {
if ('cacheWillUpdate' in plugin) {
cacheWillUpdatePlugin = plugin;
}
}
const isValidResponse = cacheWillUpdatePlugin ?
async _getFromNetwork(request: Request, event?: ExtendableEvent) {
const response = await fetchWrapper.fetch({
request,
event,
fetchOptions: this._fetchOptions,
plugins: this._plugins,
});
// Keep the service worker while we put the request to the cache
const responseClone = response.clone();
const cachePutPromise = cacheWrapper.put({
cacheName: this._cacheName,
request,
response: responseClone,
event,
plugins: this._plugins,
});
async _getNetworkPromise({timeoutId, request, logs, event}: {
request: Request,
logs: any[],
timeoutId?: number,
event?: ExtendableEvent,
}): Promise {
let error;
let response;
try {
response = await fetchWrapper.fetch({
request,
event,
fetchOptions: this._fetchOptions,
plugins: this._plugins,
});
} catch (err) {
error = err;
}
if (timeoutId) {
clearTimeout(timeoutId);
}
if (process.env.NODE_ENV !== 'production') {
if (response) {
logs.push(`Got response from network.`);
async _getFromNetwork({request, event}: {
request: Request,
event?: ExtendableEvent,
}): Promise {
const response = await fetchWrapper.fetch({
request,
event,
fetchOptions: this._fetchOptions,
plugins: this._plugins,
});
const cachePutPromise = cacheWrapper.put({
cacheName: this._cacheName,
request,
response: response.clone(),
event,
plugins: this._plugins,
});
if (event) {
try {
async handle({event, request}: RouteHandlerCallbackOptions): Promise {
if (process.env.NODE_ENV !== 'production') {
assert!.isInstance(request, Request, {
moduleName: 'workbox-strategies',
className: 'NetworkOnly',
funcName: 'handle',
paramName: 'request',
});
}
let error;
let response;
try {
response = await fetchWrapper.fetch({
request,
event,
fetchOptions: this._fetchOptions,
plugins: this._plugins,
});
} catch (err) {
error = err;
}
if (process.env.NODE_ENV !== 'production') {
logger.groupCollapsed(
messages.strategyStart('NetworkOnly', request));
if (response) {
logger.log(`Got response from network.`);
} else {
logger.log(`Unable to get a response from the network.`);