Skip to content

Commit

Permalink
Disallow streaming upload on HTTP/1.1
Browse files Browse the repository at this point in the history
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 <yhirano@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
Reviewed-by: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1020706}
  • Loading branch information
yutakahirano authored and chromium-wpt-export-bot committed Jul 5, 2022
1 parent 3fc0804 commit e2d846a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
56 changes: 55 additions & 1 deletion fetch/api/basic/request-upload.h2.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// META: script=/common/utils.js
// META: script=/common/get-host-info.sub.js

const duplex = "half";

function testUpload(desc, url, method, createBody, expectedBody) {
const requestInit = {method};
promise_test(async () => {
Expand All @@ -17,6 +19,17 @@ function testUpload(desc, url, method, createBody, expectedBody) {
}, desc);
}

function createStream(chunks) {
return new ReadableStream({
start: (controller) => {
for (const chunk of chunks) {
controller.enqueue(chunk);
}
controller.close();
}
});
}

const url = RESOURCES_DIR + "echo-content.h2.py"

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

promise_test(async (t) => {
const body = createStream(["hello"]);
const method = "POST";
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
}, "Streaming upload with body containing a String");

promise_test(async (t) => {
const body = createStream([null]);
const method = "POST";
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
}, "Streaming upload with body containing null");

promise_test(async (t) => {
const body = createStream([33]);
const method = "POST";
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([]);
const method = "POST";
await promise_rejects_js(t, TypeError, fetch(url, { method, body, duplex }));
}, "Streaming upload should fail on a 401 response");

2 changes: 1 addition & 1 deletion fetch/api/request/request-init-stream.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test((t) => {
new Request(request, { body: "..." });
}, "Constructing a Request with a Request on which body.getReader().read() is called");

promsie_test((t) => {
promise_test(async (t) => {
const request = new Request("...", { method: "POST", body: "..." });
const reader = request.body.getReader();
await reader.read();
Expand Down

0 comments on commit e2d846a

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy