Chromium Code Reviews| 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 24239c4836f4347a712c41c4b901678217ac319a..d9699fd003ce62b7593d35e4d4ceb37a0017d24c 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." |
| @@ -322,13 +310,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,7 +541,7 @@ String Request::integrity() const |
| Request* Request::clone(ExceptionState& exceptionState) |
| { |
| - if (bodyUsed()) { |
| + if (bodyUsed() || isBodyLocked()) { |
|
hiroshige
2015/11/19 12:50:37
nit: we write "isBodyLocked() || bodyUsed()" in so
yhirano
2015/11/19 13:19:03
Done.
|
| exceptionState.throwTypeError("Request body is already used"); |
| return nullptr; |
| } |
| @@ -569,9 +555,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 |