canConstructResponseFromBodyStream.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. Copyright 2019 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. let supportStatus;
  9. /**
  10. * A utility function that determines whether the current browser supports
  11. * constructing a new `Response` from a `response.body` stream.
  12. *
  13. * @return {boolean} `true`, if the current browser can successfully
  14. * construct a `Response` from a `response.body` stream, `false` otherwise.
  15. *
  16. * @private
  17. */
  18. function canConstructResponseFromBodyStream() {
  19. if (supportStatus === undefined) {
  20. const testResponse = new Response('');
  21. if ('body' in testResponse) {
  22. try {
  23. new Response(testResponse.body);
  24. supportStatus = true;
  25. }
  26. catch (error) {
  27. supportStatus = false;
  28. }
  29. }
  30. supportStatus = false;
  31. }
  32. return supportStatus;
  33. }
  34. export { canConstructResponseFromBodyStream };