Skip to content

Commit

Permalink
Bug 1777916 [wpt PR 34686] - Introduce RequestInit.duplex, a=testonly
Browse files Browse the repository at this point in the history
Automatic update from web-platform-tests
Introduce RequestInit.duplex

This implements whatwg/fetch#1457.

Bug: 1337696
Change-Id: I3fcf6f484dc922f5a875ed658adad33631d55115
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3740889
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1020764}

--

wpt-commits: 341bf2487ba47b9810a4dfa97752ffe57fa6894f
wpt-pr: 34686
  • Loading branch information
yutakahirano authored and moz-wptsync-bot committed Jul 8, 2022
1 parent da00692 commit 54297b7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
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
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
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
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 54297b7

Please sign in to comment.