Commit d5d67485 authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

Fetch: Throw a TypeError for a keepalive request with stream body

According to the Fetch Standard, attempting to create a Request object
with a body that is a ReadableStream and the keepalive flag set should
throw a TypeError exception.

Make it do that.

Since we don't yet support upload streaming, this doesn't make much
functional difference, but it lets us pass the
external/wpt/fetch/api/request/request-keepalive.html test.

BUG=973659

Change-Id: Ib3919d28a99691cfdde640b2dfb9e695b9e0c8a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2030349
Commit-Queue: Adam Rice <ricea@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736815}
parent 93b8eb80
......@@ -19,6 +19,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_array_buffer_view.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_blob.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_form_data.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_readable_stream.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_request_init.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_url_search_params.h"
#include "third_party/blink/renderer/core/dom/abort_signal.h"
......@@ -551,8 +552,17 @@ Request* Request::CreateRequestWithRequestOrString(
// "If |init|’s body member is present and is non-null, then:"
if (!init_body.IsEmpty() && !init_body->IsNull()) {
// TODO(yhirano): Throw if keepalive flag is set and body is a
// ReadableStream. We don't support body stream setting for Request yet.
// - If |init|["keepalive"] exists and is true, then set |body| and
// |Content-Type| to the result of extracting |init|["body"], with the
// |keepalive| flag set.
// From "extract a body":
// - If the keepalive flag is set, then throw a TypeError.
if (init->hasKeepalive() && init->keepalive() &&
V8ReadableStream::HasInstance(init_body, script_state->GetIsolate())) {
exception_state.ThrowTypeError(
"Keepalive request cannot have a ReadableStream body.");
return nullptr;
}
// Perform the following steps:
// - "Let |stream| and |Content-Type| be the result of extracting
......
This is a testharness.js-based test.
PASS keepalive flag
FAIL keepalive flag with stream body assert_throws_js: function "() => {new Request('/', init)}" did not throw
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment