Skip to content

Commit

Permalink
Introduce RequestInit.duplex
Browse files Browse the repository at this point in the history
This implements whatwg/fetch#1457.

Bug: 1337696
Change-Id: I3fcf6f484dc922f5a875ed658adad33631d55115
  • Loading branch information
yutakahirano authored and chromium-wpt-export-bot committed Jul 5, 2022
1 parent 8618115 commit eb0d4cf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
19 changes: 3 additions & 16 deletions fetch/api/basic/request-upload.h2.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ 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`);

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`);
Expand All @@ -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`);
Expand All @@ -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([]);
Expand Down
1 change: 1 addition & 0 deletions fetch/api/redirect/redirect-upload.h2.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function fetchStreamRedirect(statusCode) {
controller.enqueue(encoder.encode("Test"));
controller.close();
}});
requestInit.duplex = "half";
return fetch(url, requestInit);
}

Expand Down
2 changes: 2 additions & 0 deletions fetch/api/request/request-init-contenttype.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function requestFromBody(body) {
{
method: "POST",
body,
duplex: "half",
},
);
}
Expand Down Expand Up @@ -82,6 +83,7 @@ function requestFromBodyWithOverrideMime(body) {
method: "POST",
body,
headers: { "Content-Type": OVERRIDE_MIME },
duplex: "half",
},
);
}
Expand Down
6 changes: 4 additions & 2 deletions service-workers/service-worker/fetch-event.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit eb0d4cf

Please sign in to comment.