Skip to content

Update Chrome/Firefox support for ReadableStream in Request Body#1333

Merged
Elchi3 merged 4 commits intomdn:masterfrom
anthumchris:stream-request-body
Apr 18, 2018
Merged

Update Chrome/Firefox support for ReadableStream in Request Body#1333
Elchi3 merged 4 commits intomdn:masterfrom
anthumchris:stream-request-body

Conversation

@anthumchris
Copy link
Copy Markdown
Contributor

To the best of my knowledge, Chrome and Firefox do not yet support sending ReadableStream content in Request body during HTTP requests. I think we should remove the positive indicators until this is fully supported. Tested with Chrome 67 and FF 59.

// String test - passes
post('hello');

// ReadableStream test - fails
post(new ReadableStream({
  start(controller) {
    controller.enqueue(new TextEncoder().encode('hello'));
    controller.close();
  }
}));

// Server should respond with postBody text value, indicating it was sent and received.
function post(postBody) {
  fetch('https://dev.anthum.com/post-test/', {
    body: postBody,
    headers: {'content-type': 'text/plain'},
    method: 'POST'
  })
  .then(response => response.text())
  .then(data => console.log(data))
  .catch(error => console.error(error));
}

@evilpie
Copy link
Copy Markdown
Contributor

evilpie commented Mar 12, 2018

Did you test with preferences enabled in Firefox?

@anthumchris
Copy link
Copy Markdown
Contributor Author

anthumchris commented Mar 12, 2018

@evilpie Yes, the preferences/flags were enabled. Firefox sends string "[object ReadableStream]".

@Elchi3 Elchi3 added the data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API label Mar 12, 2018
@Elchi3 Elchi3 requested a review from chrisdavidmills March 14, 2018 10:49
Copy link
Copy Markdown
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main problem here is that the description is misleading — in this data I am really talking about consuming response bodies as streams, not sending requests with streams as bodies.

I think it is worth talking about both — could you update the existing description to say something like "Consuming response body as ReadableStream", and then add an extra support block to cover the other case?

@Elchi3
Copy link
Copy Markdown
Member

Elchi3 commented Apr 17, 2018

It's not clear to me how the two blocks should look like. @chrisdavidmills can you post the JSON you'd like to see here, so that I can amend this PR? (or open a new PR to get this right and I'll close this one.) Thanks!

@chrisdavidmills
Copy link
Copy Markdown
Contributor

Something like this?

"reponse_body_readablestream": {
  "__compat": {
    "description": "Consume response body as a <code>ReadableStream</code>",
    "support": {
      "chrome": {
        "version_added": "43"
      },
      "chrome_android": {
        "version_added": "43"
      },
      "edge": {
        "version_added": null
      },
      "edge_mobile": {
        "version_added": null
      },
      "firefox": {
        "version_added": true,
        "flags": [
          {
            "type": "preference",
            "name": "dom.streams.enabled"
          },
          {
            "type": "preference",
            "name": "javascript.options.streams"
          }
        ]
      },
      "firefox_android": {
        "version_added": true,
        "flags": [
          {
            "type": "preference",
            "name": "dom.streams.enabled"
          },
          {
            "type": "preference",
            "name": "javascript.options.streams"
          }
        ]
      },
      "ie": {
        "version_added": null
      },
      "opera": {
        "version_added": null
      },
      "opera_android": {
        "version_added": null
      },
      "safari": {
        "version_added": false
      },
      "safari_ios": {
        "version_added": "10.3"
      },
      "webview_android": {
        "version_added": "43"
      }
    }
  }
},
"readablestream_request_body": {
  "__compat": {
    "description": "Send <code>ReadableStream</code> in request body",
    "support": {
      "chrome": {
        "version_added": false
      },
      "chrome_android": {
        "version_added": false
      },
      "edge": {
        "version_added": null
      },
      "edge_mobile": {
        "version_added": null
      },
      "firefox": {
        "version_added": false
      },
      "firefox_android": {
        "version_added": false
      },
      "ie": {
        "version_added": null
      },
      "opera": {
        "version_added": null
      },
      "opera_android": {
        "version_added": null
      },
      "safari": {
        "version_added": false
      },
      "safari_ios": {
        "version_added": false
      },
      "webview_android": {
        "version_added": false
      }
    }
  }
}

@Elchi3 Elchi3 changed the title remove Chrome/Firefox support for ReadableStream in Request Body Update Chrome/Firefox support for ReadableStream in Request Body Apr 18, 2018
@Elchi3 Elchi3 merged commit 1b4c054 into mdn:master Apr 18, 2018
@anthumchris anthumchris deleted the stream-request-body branch April 25, 2018 21:04
@guest271314
Copy link
Copy Markdown

Related whatwg/fetch#425, whatwg/fetch#439.

Technically a workaround is possible using async/await and passing ReadableStream to Response then calling .text() which reads the stream to completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants