Does someone know of a way to create a new Response from a ReadableStream in Microsoft Edge?
For Chrome, this is quite simple. You can just take a ReadableStream
and pass it in the constructor of Response
as the first argument. This way you can, for example, create a new Response
with say another status code from a network response, without copying the response:
fetch('https://www.baqend.com/') .then(res => new Response(res.body, { status: 222 })) .then(it => it.text()) .then(it => console.log('Text prefix ' + it.substr(0,16))) .catch(it => console.log('error: ' + it))
While this works perfectly in Chrome, Edge does not support ReadableStream
as input for the Response
constructor. The only way I get it to work in Edge is when I get the text response first (effectively copying the response and blocking the stream):
fetch('https://www.baqend.com/') .then(it => it.text()) .then(text => new Response(text, { status: 222 })) .then(it => it.text()) .then(it => console.log('Text prefix ' + it.substr(0,16))) .catch(it => console.log('error: ' + it))
Does anyone know a way to create a new Response from a Readable Stream in Edge?
PS: I am using Microsoft Edge 42.17115.1.0 (latest developer preview, since I am testing Service Workers)
PPS: The first code does not work in firefox either because firefox does not support getting a RedableStream
from Response.body
. Edge does expose Response.body
though.
Launch Microsoft Edge and head to a site like YouTube for video, Facebook for photos, or Pandora for music. Once you have the video, audio, or pictures set up, click the More ellipsis button (…) in the upper-right corner of the browser. Then select Cast media to device from the menu.
Response streams have been available in all modern browsers for a while now. They allow you to access parts of a response as they arrive from the server: const response = await fetch(url); const reader = response.
Starting in EdgeHTML 14, which ships with Windows 10 Anniversary Update, Microsoft Edge supports the Fetch API.
Display HTTP headersClick the URL of the request, under the Name column of the Requests table. Click the Headers tab.
Try this:
https://www.npmjs.com/package/web-streams-polyfill
var streams = require("web-streams-polyfill"); var readable = new streams.ReadableStream; // Or, in ES6 import { ReadableStream } from "web-streams-polyfill";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With