From d36e5d94e04a7520c16e003e55c956bc2820af70 Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Tue, 5 Jul 2022 01:28:40 -0700 Subject: [PATCH] Introduce RequestInit.duplex This implements https://github.com/whatwg/fetch/pull/1457. Bug: 1337696 Change-Id: I3fcf6f484dc922f5a875ed658adad33631d55115 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3740889 Commit-Queue: Yutaka Hirano Reviewed-by: Yoichi Osato Cr-Commit-Position: refs/heads/main@{#1020764} --- fetch/api/basic/request-upload.h2.any.js | 19 +++---------------- fetch/api/redirect/redirect-upload.h2.any.js | 1 + .../request/request-init-contenttype.any.js | 2 ++ .../service-worker/fetch-event.https.html | 6 ++++-- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/fetch/api/basic/request-upload.h2.any.js b/fetch/api/basic/request-upload.h2.any.js index e89a0399b05833..aee0ea34fdeb70 100644 --- a/fetch/api/basic/request-upload.h2.any.js +++ b/fetch/api/basic/request-upload.h2.any.js @@ -72,6 +72,7 @@ promise_test(async (test) => { const request = new Request('', { body: new ReadableStream(), method: 'POST', + duplex, }); assert_equals(request.headers.get('Content-Type'), null, `Request should not have a content-type set`); @@ -79,6 +80,7 @@ promise_test(async (test) => { const response = await fetch('data:a/a;charset=utf-8,test', { method: 'POST', body: new ReadableStream(), + duplex, }); assert_equals(await response.text(), 'test', `Response has correct body`); @@ -88,6 +90,7 @@ promise_test(async (test) => { const request = new Request('data:a/a;charset=utf-8,test', { body: new ReadableStream(), method: 'POST', + duplex, }); assert_equals(request.headers.get('Content-Type'), null, `Request should not have a content-type set`); @@ -113,22 +116,6 @@ promise_test(async (t) => { await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex })); }, "Streaming upload with body containing a number"); -promise_test(async (t) => { - const url = "/fetch/api/resources/redirect.h2.py?location=/common/blank.html"; - const body = createStream([]); - const method = "POST"; - await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex })); -}, "Streaming upload should fail on redirect (302)"); - -promise_test(async (t) => { - const url = "/fetch/api/resources/redirect.h2.py?" + - "redirect_status=303&location=/common/blank.html"; - const body = createStream([]); - const method = "POST"; - const resp = await fetch(url, { method, body, duplex }); - assert_equals(resp.status, 200, 'status'); -}, "Streaming upload should work with 303"); - promise_test(async (t) => { const url = "/fetch/api/resources/authentication.py?realm=test"; const body = createStream([]); diff --git a/fetch/api/redirect/redirect-upload.h2.any.js b/fetch/api/redirect/redirect-upload.h2.any.js index 82ec43b64e91ab..521bd3adc28bff 100644 --- a/fetch/api/redirect/redirect-upload.h2.any.js +++ b/fetch/api/redirect/redirect-upload.h2.any.js @@ -15,6 +15,7 @@ async function fetchStreamRedirect(statusCode) { controller.enqueue(encoder.encode("Test")); controller.close(); }}); + requestInit.duplex = "half"; return fetch(url, requestInit); } diff --git a/fetch/api/request/request-init-contenttype.any.js b/fetch/api/request/request-init-contenttype.any.js index d8e048c4fc994a..18a6969d4f8acd 100644 --- a/fetch/api/request/request-init-contenttype.any.js +++ b/fetch/api/request/request-init-contenttype.any.js @@ -4,6 +4,7 @@ function requestFromBody(body) { { method: "POST", body, + duplex: "half", }, ); } @@ -82,6 +83,7 @@ function requestFromBodyWithOverrideMime(body) { method: "POST", body, headers: { "Content-Type": OVERRIDE_MIME }, + duplex: "half", }, ); } diff --git a/service-workers/service-worker/fetch-event.https.html b/service-workers/service-worker/fetch-event.https.html index 771f1e319ca47e..59a0988b490f6e 100644 --- a/service-workers/service-worker/fetch-event.https.html +++ b/service-workers/service-worker/fetch-event.https.html @@ -446,7 +446,8 @@ t.add_cleanup(() => { frame.remove(); }); const res = await frame.contentWindow.fetch('simple.html?request-body', { method: 'POST', - body: rs.pipeThrough(new TextEncoderStream()) + body: rs.pipeThrough(new TextEncoderStream()), + duplex: 'half', }); assert_equals(await res.text(), 'i am the request body'); }, 'FetchEvent#body is a ReadableStream'); @@ -503,7 +504,8 @@ const echo_url = '/fetch/api/resources/echo-content.py?ignore'; const response = await frame.contentWindow.fetch(echo_url, { method: 'POST', - body: rs.pipeThrough(new TextEncoderStream()) + body: rs.pipeThrough(new TextEncoderStream()), + duplex: 'half', }); const text = await response.text(); assert_equals(text,