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

Side by Side Diff: Source/modules/fetch/Request.cpp

Issue 1056813002: [Fetch] Request.clone() should reflect body consumption. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@body-used
Patch Set: Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « LayoutTests/http/tests/fetch/script-tests/response.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 330 }
331 331
332 Request* Request::clone(ExceptionState& exceptionState) const 332 Request* Request::clone(ExceptionState& exceptionState) const
333 { 333 {
334 if (bodyUsed()) { 334 if (bodyUsed()) {
335 exceptionState.throwTypeError("Request body is already used"); 335 exceptionState.throwTypeError("Request body is already used");
336 return nullptr; 336 return nullptr;
337 } 337 }
338 338
339 FetchRequestData* request = m_request->clone(); 339 FetchRequestData* request = m_request->clone();
340 if (blobDataHandle() && isBodyConsumed()) {
341 // Currently the only methods that can consume body data without
342 // setting 'body passed' flag consume entire body (e.g. text()). Thus
343 // we can set an empty blob to the new request instead of creating a
344 // draining stream.
345 // TODO(yhirano): Fix this once Request.body is introduced.
346 OwnPtr<BlobData> blobData = BlobData::create();
347 blobData->setContentType(blobDataHandle()->type());
348 request->setBlobDataHandle(BlobDataHandle::create(blobData.release(), 0) );
349 }
350
340 Headers* headers = Headers::create(request->headerList()); 351 Headers* headers = Headers::create(request->headerList());
341 headers->setGuard(m_headers->guard()); 352 headers->setGuard(m_headers->guard());
342 Request* r = new Request(executionContext(), request, headers); 353 Request* r = new Request(executionContext(), request, headers);
343 r->suspendIfNeeded(); 354 r->suspendIfNeeded();
344 return r; 355 return r;
345 } 356 }
346 357
347 FetchRequestData* Request::passRequestData() 358 FetchRequestData* Request::passRequestData()
348 { 359 {
349 ASSERT(!bodyUsed()); 360 ASSERT(!bodyUsed());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 406 }
396 407
397 DEFINE_TRACE(Request) 408 DEFINE_TRACE(Request)
398 { 409 {
399 Body::trace(visitor); 410 Body::trace(visitor);
400 visitor->trace(m_request); 411 visitor->trace(m_request);
401 visitor->trace(m_headers); 412 visitor->trace(m_headers);
402 } 413 }
403 414
404 } // namespace blink 415 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/fetch/script-tests/response.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698