Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Unified Diff: third_party/WebKit/Source/modules/fetch/Request.cpp

Issue 1418813004: [Fetch API] Reflect spec changes of bodyUsed property (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/fetch/Request.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/Request.cpp b/third_party/WebKit/Source/modules/fetch/Request.cpp
index 6cc792b88301ee34dc12b0111f299471192655fa..b715ddff74232254d072a253d0c6f53d6119c63b 100644
--- a/third_party/WebKit/Source/modules/fetch/Request.cpp
+++ b/third_party/WebKit/Source/modules/fetch/Request.cpp
@@ -12,6 +12,7 @@
#include "core/fetch/ResourceLoaderOptions.h"
#include "core/loader/ThreadableLoader.h"
#include "modules/fetch/BodyStreamBuffer.h"
+#include "modules/fetch/DataConsumerHandleUtil.h"
#include "modules/fetch/FetchBlobDataConsumerHandle.h"
#include "modules/fetch/FetchManager.h"
#include "modules/fetch/RequestInit.h"
@@ -50,29 +51,16 @@ FetchRequestData* createCopyOfFetchRequestDataForFetch(ScriptState* scriptState,
Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Request* inputRequest, const String& inputString, RequestInit& init, ExceptionState& exceptionState)
{
- // "1. Let |temporaryBody| be null."
- BodyStreamBuffer* temporaryBody = nullptr;
-
- if (inputRequest) {
- // We check bodyUsed even when the body is null in spite of the
- // spec. See https://github.com/whatwg/fetch/issues/61 for details.
- if (inputRequest->bodyUsed()) {
- exceptionState.throwTypeError("Cannot construct a Request with a Request object that has already been used.");
- return nullptr;
- }
+ // "1. If |input| is a Request object and it is disturbed, throw a
+ // TypeError.
+ if (inputRequest && inputRequest->bodyUsed()) {
+ exceptionState.throwTypeError("Cannot construct a Request with a Request object that has already been used.");
+ return nullptr;
}
- // "2. If |input| is a Request object and |input|'s body is non-null, run
- // these substeps:"
- if (inputRequest && inputRequest->hasBody()) {
- // "1. If |input|'s used flag is set, throw a TypeError."
- // "2. Set |temporaryBody| to |input|'s body."
- if (inputRequest->bodyUsed()) {
- exceptionState.throwTypeError("Cannot construct a Request with a Request object that has already been used.");
- return nullptr;
- }
- temporaryBody = inputRequest->bodyBuffer();
- }
+ // "2. Let |temporaryBody| be |input|'s request's body if |input| is a
+ // Request object, and null otherwise.
+ BodyStreamBuffer* temporaryBody = inputRequest ? inputRequest->bodyBuffer() : nullptr;
// "3. Let |request| be |input|'s request, if |input| is a Request object,
// and a new request otherwise."
@@ -300,7 +288,7 @@ Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req
if (temporaryBody)
r->m_request->setBuffer(temporaryBody);
- // https://w3c.github.io/webappsec/specs/credentialmanagement/#monkey-patching-fetch-2
+ // https://w3c.github.io/webappsec-credential-management/#monkey-patching-fetch-2
if (init.opaque || (inputRequest && inputRequest->opaque()))
r->makeOpaque();
@@ -310,13 +298,11 @@ Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req
// "35. If |input| is a Request object and |input|'s body is non-null, run
// these substeps:"
- // We set bodyUsed even when the body is null in spite of the
- // spec. See https://github.com/whatwg/fetch/issues/61 for details.
- if (inputRequest) {
- // "1. Set |input|'s body to null."
- inputRequest->m_request->setBuffer(nullptr);
- // "2. Set |input|'s used flag."
- inputRequest->setBodyPassed();
+ if (inputRequest && inputRequest->bodyBuffer()) {
+ // "1. Set |input|'s body to an empty byte stream."
+ inputRequest->m_request->setBuffer(new BodyStreamBuffer(createFetchDataConsumerHandleFromWebHandle(createDoneDataConsumerHandle())));
+ // "2. Set |input|'s disturbed flag."
+ inputRequest->bodyBuffer()->stream()->setIsDisturbed();
}
// "36. Return |r|."
@@ -555,9 +541,7 @@ Request* Request::clone(ExceptionState& exceptionState)
FetchRequestData* Request::passRequestData()
{
ASSERT(!bodyUsed());
- setBodyPassed();
- FetchRequestData* newRequestData = m_request->pass(executionContext());
- return newRequestData;
+ return m_request->pass(executionContext());
}
bool Request::hasBody() const

Powered by Google App Engine
This is Rietveld 408576698