| 1 | /*
|
|---|
| 2 | Copyright 2018 Google LLC
|
|---|
| 3 |
|
|---|
| 4 | Use of this source code is governed by an MIT-style
|
|---|
| 5 | license that can be found in the LICENSE file or at
|
|---|
| 6 | https://opensource.org/licenses/MIT.
|
|---|
| 7 | */
|
|---|
| 8 | import { createHeaders } from './utils/createHeaders.js';
|
|---|
| 9 | import { concatenate } from './concatenate.js';
|
|---|
| 10 | import './_version.js';
|
|---|
| 11 | /**
|
|---|
| 12 | * Takes multiple source Promises, each of which could resolve to a Response, a
|
|---|
| 13 | * ReadableStream, or a [BodyInit](https://fetch.spec.whatwg.org/#bodyinit),
|
|---|
| 14 | * along with a
|
|---|
| 15 | * [HeadersInit](https://fetch.spec.whatwg.org/#typedefdef-headersinit).
|
|---|
| 16 | *
|
|---|
| 17 | * Returns an object exposing a Response whose body consists of each individual
|
|---|
| 18 | * stream's data returned in sequence, along with a Promise which signals when
|
|---|
| 19 | * the stream is finished (useful for passing to a FetchEvent's waitUntil()).
|
|---|
| 20 | *
|
|---|
| 21 | * @param {Array<Promise<workbox-streams.StreamSource>>} sourcePromises
|
|---|
| 22 | * @param {HeadersInit} [headersInit] If there's no `Content-Type` specified,
|
|---|
| 23 | * `'text/html'` will be used by default.
|
|---|
| 24 | * @return {Object<{done: Promise, response: Response}>}
|
|---|
| 25 | *
|
|---|
| 26 | * @memberof workbox-streams
|
|---|
| 27 | */
|
|---|
| 28 | function concatenateToResponse(sourcePromises, headersInit) {
|
|---|
| 29 | const { done, stream } = concatenate(sourcePromises);
|
|---|
| 30 | const headers = createHeaders(headersInit);
|
|---|
| 31 | const response = new Response(stream, { headers });
|
|---|
| 32 | return { done, response };
|
|---|
| 33 | }
|
|---|
| 34 | export { concatenateToResponse };
|
|---|