Commit 14490935 authored by Luca Casonato's avatar Luca Casonato Committed by moz-wptsync-bot
Browse files

Bug 1721076 [wpt PR 29698] - fetch: resp body shouldn't buffer if content-type...

Bug 1721076 [wpt PR 29698] - fetch: resp body shouldn't buffer if content-type is missing, a=testonly

Automatic update from web-platform-tests
Fetch: resp body shouldn't buffer if content-type is missing

--

wpt-commits: 6165b734019bc0b1fb91868f348ec7fc58543f99
wpt-pr: 29698
parent d3ee3993
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
// META: global=window,worker
// META: script=../resources/utils.js

function streamBody(reader, test, count) {
function streamBody(reader, test, count = 0) {
  return reader.read().then(function(data) {
    if (!data.done && count < 2) {
      count += 1;
@@ -18,12 +18,23 @@ function streamBody(reader, test, count) {
//count is large enough to let the UA deliver the body before it is completely retrieved
promise_test(function(test) {
  return fetch(RESOURCES_DIR + "trickle.py?ms=30&count=100").then(function(resp) {
    var count = 0;
    if (resp.body)
      return streamBody(resp.body.getReader(), test, count);
      return streamBody(resp.body.getReader(), test);
    else
      test.step(function() {
        assert_unreached( "Body does not exist in response");
      });
  });
}, "Stream response's body");
}, "Stream response's body when content-type is present");

// This test makes sure that the response body is not buffered if no content type is provided.
promise_test(function(test) {
  return fetch(RESOURCES_DIR + "trickle.py?ms=300&count=10&notype=true").then(function(resp) {
    if (resp.body)
      return streamBody(resp.body.getReader(), test);
    else
      test.step(function() {
        assert_unreached( "Body does not exist in response");
      });
  });
}, "Stream response's body when content-type is not present");
+2 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ def main(request, response):
    # Read request body
    request.body
    time.sleep(delay)
    if not b"notype" in request.GET:
        response.headers.set(b"Content-type", b"text/plain")
    response.write_status_headers()
    time.sleep(delay)