Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/fetch/Request.h" | 6 #include "modules/fetch/Request.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 // FIXME: Set cache mode. | 42 // FIXME: Set cache mode. |
| 43 // TODO(yhirano): Set redirect mode. | 43 // TODO(yhirano): Set redirect mode. |
| 44 return request; | 44 return request; |
| 45 } | 45 } |
| 46 | 46 |
| 47 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req uest* inputRequest, const String& inputString, const RequestInit& init, Exceptio nState& exceptionState) | 47 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req uest* inputRequest, const String& inputString, const RequestInit& init, Exceptio nState& exceptionState) |
| 48 { | 48 { |
| 49 // "1. Let |temporaryBody| be null." | 49 // "1. Let |temporaryBody| be null." |
| 50 RefPtr<BlobDataHandle> temporaryBody; | 50 RefPtr<BlobDataHandle> temporaryBody; |
| 51 | 51 |
| 52 if (inputRequest) { | |
| 53 // We check bodyUsed even when the body is null in spite of the | |
| 54 // spec. See https://github.com/whatwg/fetch/issues/61 for details. | |
| 55 if (inputRequest->bodyUsed()) { | |
|
tyoshino (SeeGerritForStatus)
2015/06/18 06:34:34
are these if-s separated intentionally?
yhirano
2015/06/18 06:44:24
Yes.
| |
| 56 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used."); | |
| 57 return nullptr; | |
| 58 } | |
| 59 } | |
| 60 | |
| 52 // "2. If |input| is a Request object and |input|'s body is non-null, run | 61 // "2. If |input| is a Request object and |input|'s body is non-null, run |
| 53 // these substeps:" | 62 // these substeps:" |
| 54 if (inputRequest && inputRequest->hasBody()) { | 63 if (inputRequest && inputRequest->hasBody()) { |
| 55 // "1. If |input|'s used flag is set, throw a TypeError." | 64 // "1. If |input|'s used flag is set, throw a TypeError." |
| 56 // "2. Set |temporaryBody| to |input|'s body." | 65 // "2. Set |temporaryBody| to |input|'s body." |
| 57 if (inputRequest->bodyUsed()) { | 66 if (inputRequest->bodyUsed()) { |
| 58 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used."); | 67 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used."); |
| 59 return nullptr; | 68 return nullptr; |
| 60 } | 69 } |
| 61 if (inputRequest->isBodyConsumed()) { | 70 if (inputRequest->isBodyConsumed()) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 | 245 |
| 237 // "29. Set |r|'s body to |temporaryBody|. | 246 // "29. Set |r|'s body to |temporaryBody|. |
| 238 r->setBodyBlobHandle(temporaryBody.release()); | 247 r->setBodyBlobHandle(temporaryBody.release()); |
| 239 | 248 |
| 240 // "30. Set |r|'s MIME type to the result of extracting a MIME type from | 249 // "30. Set |r|'s MIME type to the result of extracting a MIME type from |
| 241 // |r|'s request's header list." | 250 // |r|'s request's header list." |
| 242 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); | 251 r->m_request->setMIMEType(r->m_request->headerList()->extractMIMEType()); |
| 243 | 252 |
| 244 // "31. If |input| is a Request object and |input|'s body is non-null, run | 253 // "31. If |input| is a Request object and |input|'s body is non-null, run |
| 245 // these substeps:" | 254 // these substeps:" |
| 246 if (inputRequest && inputRequest->hasBody()) { | 255 // We set bodyUsed even when the body is null in spite of the |
| 256 // spec. See https://github.com/whatwg/fetch/issues/61 for details. | |
| 257 if (inputRequest) { | |
| 247 // "1. Set |input|'s body to null." | 258 // "1. Set |input|'s body to null." |
| 248 inputRequest->setBodyBlobHandle(nullptr); | 259 inputRequest->setBodyBlobHandle(nullptr); |
| 249 // "2. Set |input|'s used flag." | 260 // "2. Set |input|'s used flag." |
| 250 inputRequest->lockBody(PassBody); | 261 inputRequest->lockBody(PassBody); |
| 251 } | 262 } |
| 252 | 263 |
| 253 // "32. Return |r|." | 264 // "32. Return |r|." |
| 254 return r; | 265 return r; |
| 255 } | 266 } |
| 256 | 267 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 } | 544 } |
| 534 | 545 |
| 535 DEFINE_TRACE(Request) | 546 DEFINE_TRACE(Request) |
| 536 { | 547 { |
| 537 Body::trace(visitor); | 548 Body::trace(visitor); |
| 538 visitor->trace(m_request); | 549 visitor->trace(m_request); |
| 539 visitor->trace(m_headers); | 550 visitor->trace(m_headers); |
| 540 } | 551 } |
| 541 | 552 |
| 542 } // namespace blink | 553 } // namespace blink |
| OLD | NEW |