Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

48 linhas
1.7 KiB

  1. /*
  2. Copyright 2018 Google Inc. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. import {createHeaders} from './utils/createHeaders.mjs';
  14. import {concatenate} from './concatenate.mjs';
  15. import './_version.mjs';
  16. /**
  17. * Takes multiple source Promises, each of which could resolve to a Response, a
  18. * ReadableStream, or a [BodyInit](https://fetch.spec.whatwg.org/#bodyinit),
  19. * along with a
  20. * [HeadersInit](https://fetch.spec.whatwg.org/#typedefdef-headersinit).
  21. *
  22. * Returns an object exposing a Response whose body consists of each individual
  23. * stream's data returned in sequence, along with a Promise which signals when
  24. * the stream is finished (useful for passing to a FetchEvent's waitUntil()).
  25. *
  26. * @param {Array<Promise<workbox.streams.StreamSource>>} sourcePromises
  27. * @param {HeadersInit} [headersInit] If there's no `Content-Type` specified,
  28. * `'text/html'` will be used by default.
  29. * @return {Object<{done: Promise, response: Response}>}
  30. *
  31. * @memberof workbox.streams
  32. */
  33. function concatenateToResponse(sourcePromises, headersInit) {
  34. const {done, stream} = concatenate(sourcePromises);
  35. const headers = createHeaders(headersInit);
  36. const response = new Response(stream, {headers});
  37. return {done, response};
  38. }
  39. export {concatenateToResponse};