createHeaders.mjs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.mjs';
  8. /**
  9. * This is a utility method that determines whether the current browser supports
  10. * the features required to create streamed responses. Currently, it checks if
  11. * [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
  12. * is available.
  13. *
  14. * @param {HeadersInit} [headersInit] If there's no `Content-Type` specified,
  15. * `'text/html'` will be used by default.
  16. * @return {boolean} `true`, if the current browser meets the requirements for
  17. * streaming responses, and `false` otherwise.
  18. *
  19. * @memberof workbox.streams
  20. */
  21. function createHeaders(headersInit = {}) {
  22. // See https://github.com/GoogleChrome/workbox/issues/1461
  23. const headers = new Headers(headersInit);
  24. if (!headers.has('content-type')) {
  25. headers.set('content-type', 'text/html');
  26. }
  27. return headers;
  28. }
  29. export {createHeaders};