1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { logger } from 'workbox-core/_private/logger.js';
- import { createHeaders } from './utils/createHeaders.js';
- import { concatenateToResponse } from './concatenateToResponse.js';
- import { isSupported } from './isSupported.js';
- import './_version.js';
- function strategy(sourceFunctions, headersInit) {
- return async ({ event, request, url, params }) => {
- const sourcePromises = sourceFunctions.map((fn) => {
-
- return Promise.resolve(fn({ event, request, url, params }));
- });
- if (isSupported()) {
- const { done, response } = concatenateToResponse(sourcePromises, headersInit);
- if (event) {
- event.waitUntil(done);
- }
- return response;
- }
- if (process.env.NODE_ENV !== 'production') {
- logger.log(`The current browser doesn't support creating response ` +
- `streams. Falling back to non-streaming response instead.`);
- }
-
-
- const blobPartsPromises = sourcePromises.map(async (sourcePromise) => {
- const source = await sourcePromise;
- if (source instanceof Response) {
- return source.blob();
- }
- else {
-
-
-
-
- return new Response(source).blob();
- }
- });
- const blobParts = await Promise.all(blobPartsPromises);
- const headers = createHeaders(headersInit);
-
-
- return new Response(new Blob(blobParts), { headers });
- };
- }
- export { strategy };
|