Skip to content

Commit ec63eb9

Browse files
yutakahiranoChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
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 66cf36f commit ec63eb9

25 files changed

+158
-426
lines changed

services/network/chunked_data_pipe_upload_data_stream.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ void ChunkedDataPipeUploadDataStream::OnSizeReceived(int32_t status,
203203
// Clear |buf_| as well, so it's only non-null while there's a pending read.
204204
buf_ = nullptr;
205205
buf_len_ = 0;
206+
chunked_data_pipe_getter_.reset();
206207

207208
OnReadCompleted(status_);
208209

third_party/blink/renderer/core/fetch/fetch_manager.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,6 @@ void FetchManager::Loader::PerformHTTPFetch() {
790790
resolver_->GetScriptState(),
791791
pending_remote.InitWithNewPipeAndPassReceiver());
792792
request.MutableBody().SetStreamBody(std::move(pending_remote));
793-
request.SetAllowHTTP1ForStreamingUpload(
794-
fetch_request_data_->AllowHTTP1ForStreamingUpload());
795793
}
796794
}
797795
}

third_party/blink/renderer/core/fetch/fetch_request_data.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ FetchRequestData* FetchRequestData::CloneExceptBody() {
227227
request->is_history_navigation_ = is_history_navigation_;
228228
request->window_id_ = window_id_;
229229
request->trust_token_params_ = trust_token_params_;
230-
request->allow_http1_for_streaming_upload_ =
231-
allow_http1_for_streaming_upload_;
232230
return request;
233231
}
234232

third_party/blink/renderer/core/fetch/fetch_request_data.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ class CORE_EXPORT FetchRequestData final
154154
trust_token_params_ = std::move(trust_token_params);
155155
}
156156

157-
void SetAllowHTTP1ForStreamingUpload(bool allow) {
158-
allow_http1_for_streaming_upload_ = allow;
159-
}
160-
bool AllowHTTP1ForStreamingUpload() const {
161-
return allow_http1_for_streaming_upload_;
162-
}
163-
164157
void Trace(Visitor*) const;
165158

166159
private:
@@ -212,7 +205,6 @@ class CORE_EXPORT FetchRequestData final
212205
HeapMojoRemote<network::mojom::blink::URLLoaderFactory> url_loader_factory_;
213206
base::UnguessableToken window_id_;
214207
Member<ExecutionContext> execution_context_;
215-
bool allow_http1_for_streaming_upload_ = false;
216208
};
217209

218210
} // namespace blink

third_party/blink/renderer/core/fetch/request.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,6 @@ Request* Request::CreateRequestWithRequestOrString(
578578

579579
request->SetTrustTokenParams(std::move(params));
580580
}
581-
if (init->hasAllowHTTP1ForStreamingUpload()) {
582-
request->SetAllowHTTP1ForStreamingUpload(
583-
init->allowHTTP1ForStreamingUpload());
584-
}
585581

586582
// "Let |r| be a new Request object associated with |request| and a new
587583
// Headers object whose guard is "request"."

third_party/blink/renderer/core/fetch/request_init.idl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dictionary RequestInit {
2727
// contexts, this has to be enforced after the fact because the
2828
// SecureContext IDL attribute doesn't affect dictionary members.
2929
[RuntimeEnabled=TrustTokens] TrustToken trustToken;
30-
[RuntimeEnabled=FetchUploadStreaming] boolean allowHTTP1ForStreamingUpload;
3130
// TODO(domfarolino): add support for RequestInit window member.
3231
//any window; // can only be set to null
3332
};

third_party/blink/renderer/platform/loader/fetch/fetch_api_request_body_mojom_traits.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ StructTraits<blink::mojom::FetchAPIRequestBodyDataView,
2727
if (auto form_body = mutable_body.FormBody()) {
2828
// Here we need to keep the original body, because other members such as
2929
// `identifier` are on the form body.
30-
network_body = NetworkResourceRequestBodyFor(
31-
blink::ResourceRequestBody(form_body),
32-
/*allow_http1_for_streaming_upload=*/false);
30+
network_body =
31+
NetworkResourceRequestBodyFor(blink::ResourceRequestBody(form_body));
3332
} else if (mutable_body.StreamBody()) {
3433
// Here we don't need to keep the original body (and it's impossible to do
3534
// so, because the streaming body is not copyable).
36-
network_body = NetworkResourceRequestBodyFor(
37-
std::move(mutable_body), /*allow_http1_for_streaming_upload=*/false);
35+
network_body = NetworkResourceRequestBodyFor(std::move(mutable_body));
3836
}
3937
if (!network_body) {
4038
return WTF::Vector<network::DataElement>();

third_party/blink/renderer/platform/loader/fetch/resource_request.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,6 @@ class PLATFORM_EXPORT ResourceRequestHead {
512512
// |url|,
513513
bool CanDisplay(const KURL&) const;
514514

515-
void SetAllowHTTP1ForStreamingUpload(bool allow) {
516-
allowHTTP1ForStreamingUpload_ = allow;
517-
}
518-
bool AllowHTTP1ForStreamingUpload() const {
519-
return allowHTTP1ForStreamingUpload_;
520-
}
521-
522515
// The original destination of a request passed through by a service worker.
523516
network::mojom::RequestDestination GetOriginalDestination() const {
524517
return original_destination_;
@@ -636,8 +629,6 @@ class PLATFORM_EXPORT ResourceRequestHead {
636629
// the prefetch cache will be restricted to top-level-navigations.
637630
bool prefetch_maybe_for_top_level_navigation_ = false;
638631

639-
bool allowHTTP1ForStreamingUpload_ = false;
640-
641632
// This is used when fetching preload header requests from cross-origin
642633
// prefetch responses. The browser process uses this token to ensure the
643634
// request is cached correctly.

third_party/blink/renderer/platform/loader/fetch/url_loader/request_conversion.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ void PopulateResourceRequestBody(const EncodedFormData& src,
233233
} // namespace
234234

235235
scoped_refptr<network::ResourceRequestBody> NetworkResourceRequestBodyFor(
236-
ResourceRequestBody src_body,
237-
bool allow_http1_for_streaming_upload) {
236+
ResourceRequestBody src_body) {
238237
scoped_refptr<network::ResourceRequestBody> dest_body;
239238
if (const EncodedFormData* form_body = src_body.FormBody().get()) {
240239
dest_body = base::MakeRefCounted<network::ResourceRequestBody>();
@@ -247,8 +246,9 @@ scoped_refptr<network::ResourceRequestBody> NetworkResourceRequestBodyFor(
247246
dest_body->SetToChunkedDataPipe(
248247
ToCrossVariantMojoType(std::move(stream_body)),
249248
network::ResourceRequestBody::ReadOnlyOnce(true));
250-
dest_body->SetAllowHTTP1ForStreamingUpload(
251-
allow_http1_for_streaming_upload);
249+
}
250+
if (dest_body) {
251+
dest_body->SetAllowHTTP1ForStreamingUpload(false);
252252
}
253253
return dest_body;
254254
}
@@ -375,8 +375,7 @@ void PopulateResourceRequest(const ResourceRequestHead& src,
375375

376376
dest->is_favicon = src.IsFavicon();
377377

378-
dest->request_body = NetworkResourceRequestBodyFor(
379-
std::move(src_body), src.AllowHTTP1ForStreamingUpload());
378+
dest->request_body = NetworkResourceRequestBodyFor(std::move(src_body));
380379
if (dest->request_body) {
381380
DCHECK_NE(dest->method, net::HttpRequestHeaders::kGetMethod);
382381
DCHECK_NE(dest->method, net::HttpRequestHeaders::kHeadMethod);

third_party/blink/renderer/platform/loader/fetch/url_loader/request_conversion.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class ResourceRequestHead;
2020
class ResourceRequestBody;
2121

2222
scoped_refptr<network::ResourceRequestBody> NetworkResourceRequestBodyFor(
23-
const ResourceRequestBody src_body,
24-
bool allow_http1_for_streaming_upload);
23+
const ResourceRequestBody src_body);
2524

2625
void PopulateResourceRequest(const ResourceRequestHead& src,
2726
ResourceRequestBody src_body,

third_party/blink/web_tests/external/wpt/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+

third_party/blink/web_tests/external/wpt/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();

third_party/blink/web_tests/flag-specific/disable-site-isolation-trials/external/wpt/fetch/api/request/request-init-stream.any.sharedworker-expected.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)