Skip to content

Commit 341bf24

Browse files
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 <[email protected]> Reviewed-by: Yoichi Osato <[email protected]> Cr-Commit-Position: refs/heads/main@{#1020764}
1 parent 8618115 commit 341bf24

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

Diff for: fetch/api/basic/request-upload.h2.any.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ promise_test(async (test) => {
7272
const request = new Request('', {
7373
body: new ReadableStream(),
7474
method: 'POST',
75+
duplex,
7576
});
7677

7778
assert_equals(request.headers.get('Content-Type'), null, `Request should not have a content-type set`);
7879

7980
const response = await fetch('data:a/a;charset=utf-8,test', {
8081
method: 'POST',
8182
body: new ReadableStream(),
83+
duplex,
8284
});
8385

8486
assert_equals(await response.text(), 'test', `Response has correct body`);
@@ -88,6 +90,7 @@ promise_test(async (test) => {
8890
const request = new Request('data:a/a;charset=utf-8,test', {
8991
body: new ReadableStream(),
9092
method: 'POST',
93+
duplex,
9194
});
9295

9396
assert_equals(request.headers.get('Content-Type'), null, `Request should not have a content-type set`);
@@ -113,22 +116,6 @@ promise_test(async (t) => {
113116
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
114117
}, "Streaming upload with body containing a number");
115118

116-
promise_test(async (t) => {
117-
const url = "/fetch/api/resources/redirect.h2.py?location=/common/blank.html";
118-
const body = createStream([]);
119-
const method = "POST";
120-
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
121-
}, "Streaming upload should fail on redirect (302)");
122-
123-
promise_test(async (t) => {
124-
const url = "/fetch/api/resources/redirect.h2.py?" +
125-
"redirect_status=303&location=/common/blank.html";
126-
const body = createStream([]);
127-
const method = "POST";
128-
const resp = await fetch(url, { method, body, duplex });
129-
assert_equals(resp.status, 200, 'status');
130-
}, "Streaming upload should work with 303");
131-
132119
promise_test(async (t) => {
133120
const url = "/fetch/api/resources/authentication.py?realm=test";
134121
const body = createStream([]);

Diff for: fetch/api/redirect/redirect-upload.h2.any.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ async function fetchStreamRedirect(statusCode) {
1515
controller.enqueue(encoder.encode("Test"));
1616
controller.close();
1717
}});
18+
requestInit.duplex = "half";
1819
return fetch(url, requestInit);
1920
}
2021

Diff for: fetch/api/request/request-init-contenttype.any.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function requestFromBody(body) {
44
{
55
method: "POST",
66
body,
7+
duplex: "half",
78
},
89
);
910
}
@@ -82,6 +83,7 @@ function requestFromBodyWithOverrideMime(body) {
8283
method: "POST",
8384
body,
8485
headers: { "Content-Type": OVERRIDE_MIME },
86+
duplex: "half",
8587
},
8688
);
8789
}

Diff for: service-workers/service-worker/fetch-event.https.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,8 @@
446446
t.add_cleanup(() => { frame.remove(); });
447447
const res = await frame.contentWindow.fetch('simple.html?request-body', {
448448
method: 'POST',
449-
body: rs.pipeThrough(new TextEncoderStream())
449+
body: rs.pipeThrough(new TextEncoderStream()),
450+
duplex: 'half',
450451
});
451452
assert_equals(await res.text(), 'i am the request body');
452453
}, 'FetchEvent#body is a ReadableStream');
@@ -503,7 +504,8 @@
503504
const echo_url = '/fetch/api/resources/echo-content.py?ignore';
504505
const response = await frame.contentWindow.fetch(echo_url, {
505506
method: 'POST',
506-
body: rs.pipeThrough(new TextEncoderStream())
507+
body: rs.pipeThrough(new TextEncoderStream()),
508+
duplex: 'half',
507509
});
508510
const text = await response.text();
509511
assert_equals(text,

0 commit comments

Comments
 (0)