createHeaders.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  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.js';
  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. * @private
  15. * @param {HeadersInit} [headersInit] If there's no `Content-Type` specified,
  16. * `'text/html'` will be used by default.
  17. * @return {boolean} `true`, if the current browser meets the requirements for
  18. * streaming responses, and `false` otherwise.
  19. *
  20. * @memberof module:workbox-streams
  21. */
  22. function createHeaders(headersInit = {}) {
  23. // See https://github.com/GoogleChrome/workbox/issues/1461
  24. const headers = new Headers(headersInit);
  25. if (!headers.has('content-type')) {
  26. headers.set('content-type', 'text/html');
  27. }
  28. return headers;
  29. }
  30. export { createHeaders };