Skip to content

Commit 8618115

Browse files
Disallow streaming upload on HTTP/1.1
We decided not to allow the streaming upload feature on HTTP/1.1. Remove the feature, and move tests accordingly. See also: whatwg/fetch#966 Bug: 688906 Change-Id: I4e616469aad2378495ad81ba9034ca034f8ab1b9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3734308 Commit-Queue: Yutaka Hirano <[email protected]> Reviewed-by: Sam McNally <[email protected]> Reviewed-by: Yoichi Osato <[email protected]> Cr-Commit-Position: refs/heads/main@{#1020706}
1 parent 3fc0804 commit 8618115

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

fetch/api/basic/request-upload.h2.any.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// META: script=/common/utils.js
44
// META: script=/common/get-host-info.sub.js
55

6+
const duplex = "half";
7+
68
function testUpload(desc, url, method, createBody, expectedBody) {
79
const requestInit = {method};
810
promise_test(async () => {
@@ -17,6 +19,17 @@ function testUpload(desc, url, method, createBody, expectedBody) {
1719
}, desc);
1820
}
1921

22+
function createStream(chunks) {
23+
return new ReadableStream({
24+
start: (controller) => {
25+
for (const chunk of chunks) {
26+
controller.enqueue(chunk);
27+
}
28+
controller.close();
29+
}
30+
});
31+
}
32+
2033
const url = RESOURCES_DIR + "echo-content.h2.py"
2134

2235
testUpload("Fetch with POST with empty ReadableStream", url,
@@ -49,7 +62,7 @@ promise_test(async (test) => {
4962
"/fetch/connection-pool/resources/network-partition-key.py?"
5063
+ `status=421&uuid=${token()}&partition_id=${self.origin}`
5164
+ `&dispatch=check_partition&addcounter=true`,
52-
{method: "POST", body: body});
65+
{method: "POST", body: body, duplex});
5366
assert_equals(resp.status, 421);
5467
const text = await resp.text();
5568
assert_equals(text, "ok. Request was sent 1 times. 1 connections were created.");
@@ -82,3 +95,44 @@ promise_test(async (test) => {
8295
assert_equals(await response.text(), 'test', `Response has correct body`);
8396
}, "Feature detect for POST with ReadableStream, using request object");
8497

98+
promise_test(async (t) => {
99+
const body = createStream(["hello"]);
100+
const method = "POST";
101+
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
102+
}, "Streaming upload with body containing a String");
103+
104+
promise_test(async (t) => {
105+
const body = createStream([null]);
106+
const method = "POST";
107+
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
108+
}, "Streaming upload with body containing null");
109+
110+
promise_test(async (t) => {
111+
const body = createStream([33]);
112+
const method = "POST";
113+
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
114+
}, "Streaming upload with body containing a number");
115+
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+
132+
promise_test(async (t) => {
133+
const url = "/fetch/api/resources/authentication.py?realm=test";
134+
const body = createStream([]);
135+
const method = "POST";
136+
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
137+
}, "Streaming upload should fail on a 401 response");
138+

fetch/api/request/request-init-stream.any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test((t) => {
5050
new Request(request, { body: "..." });
5151
}, "Constructing a Request with a Request on which body.getReader().read() is called");
5252

53-
promsie_test((t) => {
53+
promise_test(async (t) => {
5454
const request = new Request("...", { method: "POST", body: "..." });
5555
const reader = request.body.getReader();
5656
await reader.read();

0 commit comments

Comments
 (0)