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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/FetchManager.cpp

Issue 2433363002: Use net::HttpResponseHeaders::IsRedirectResponseCode() from Blink (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/fetch/Response.cpp » ('j') | 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 "modules/fetch/FetchManager.h" 5 #include "modules/fetch/FetchManager.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8ThrowException.h" 10 #include "bindings/core/v8/V8ThrowException.h"
(...skipping 12 matching lines...) Expand all
23 #include "core/page/Page.h" 23 #include "core/page/Page.h"
24 #include "modules/fetch/Body.h" 24 #include "modules/fetch/Body.h"
25 #include "modules/fetch/BodyStreamBuffer.h" 25 #include "modules/fetch/BodyStreamBuffer.h"
26 #include "modules/fetch/BytesConsumer.h" 26 #include "modules/fetch/BytesConsumer.h"
27 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" 27 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h"
28 #include "modules/fetch/FetchRequestData.h" 28 #include "modules/fetch/FetchRequestData.h"
29 #include "modules/fetch/FormDataBytesConsumer.h" 29 #include "modules/fetch/FormDataBytesConsumer.h"
30 #include "modules/fetch/Response.h" 30 #include "modules/fetch/Response.h"
31 #include "modules/fetch/ResponseInit.h" 31 #include "modules/fetch/ResponseInit.h"
32 #include "platform/HTTPNames.h" 32 #include "platform/HTTPNames.h"
33 #include "platform/network/NetworkUtils.h"
33 #include "platform/network/ResourceError.h" 34 #include "platform/network/ResourceError.h"
34 #include "platform/network/ResourceRequest.h" 35 #include "platform/network/ResourceRequest.h"
35 #include "platform/network/ResourceResponse.h" 36 #include "platform/network/ResourceResponse.h"
36 #include "platform/weborigin/SchemeRegistry.h" 37 #include "platform/weborigin/SchemeRegistry.h"
37 #include "platform/weborigin/SecurityOrigin.h" 38 #include "platform/weborigin/SecurityOrigin.h"
38 #include "platform/weborigin/SecurityPolicy.h" 39 #include "platform/weborigin/SecurityPolicy.h"
39 #include "public/platform/WebURLRequest.h" 40 #include "public/platform/WebURLRequest.h"
40 #include "wtf/HashSet.h" 41 #include "wtf/HashSet.h"
41 #include "wtf/Vector.h" 42 #include "wtf/Vector.h"
42 #include "wtf/text/WTFString.h" 43 #include "wtf/text/WTFString.h"
43 #include <memory> 44 #include <memory>
44 45
45 namespace blink { 46 namespace blink {
46 47
47 namespace { 48 namespace {
48 49
49 bool IsRedirectStatusCode(int statusCode) {
50 return (statusCode == 301 || statusCode == 302 || statusCode == 303 ||
51 statusCode == 307 || statusCode == 308);
52 }
53
54 class SRIBytesConsumer final : public BytesConsumer { 50 class SRIBytesConsumer final : public BytesConsumer {
55 public: 51 public:
56 // BytesConsumer implementation 52 // BytesConsumer implementation
57 Result beginRead(const char** buffer, size_t* available) override { 53 Result beginRead(const char** buffer, size_t* available) override {
58 if (!m_underlying) { 54 if (!m_underlying) {
59 *buffer = nullptr; 55 *buffer = nullptr;
60 *available = 0; 56 *available = 0;
61 return m_isCancelled ? Result::Done : Result::ShouldWait; 57 return m_isCancelled ? Result::Done : Result::ShouldWait;
62 } 58 }
63 return m_underlying->beginRead(buffer, available); 59 return m_underlying->beginRead(buffer, available);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 responseData->setStatus(response.httpStatusCode()); 422 responseData->setStatus(response.httpStatusCode());
427 responseData->setStatusMessage(response.httpStatusText()); 423 responseData->setStatusMessage(response.httpStatusText());
428 for (auto& it : response.httpHeaderFields()) 424 for (auto& it : response.httpHeaderFields())
429 responseData->headerList()->append(it.key, it.value); 425 responseData->headerList()->append(it.key, it.value);
430 responseData->setURL(response.url()); 426 responseData->setURL(response.url());
431 responseData->setMIMEType(response.mimeType()); 427 responseData->setMIMEType(response.mimeType());
432 responseData->setResponseTime(response.responseTime()); 428 responseData->setResponseTime(response.responseTime());
433 429
434 FetchResponseData* taintedResponse = nullptr; 430 FetchResponseData* taintedResponse = nullptr;
435 431
436 if (IsRedirectStatusCode(m_responseHttpStatusCode)) { 432 if (NetworkUtils::isRedirectResponseCode(m_responseHttpStatusCode)) {
437 Vector<String> locations; 433 Vector<String> locations;
438 responseData->headerList()->getAll(HTTPNames::Location, locations); 434 responseData->headerList()->getAll(HTTPNames::Location, locations);
439 if (locations.size() > 1) { 435 if (locations.size() > 1) {
440 performNetworkError("Multiple Location header."); 436 performNetworkError("Multiple Location header.");
441 return; 437 return;
442 } 438 }
443 if (locations.size() == 1) { 439 if (locations.size() == 1) {
444 KURL locationURL(m_request->url(), locations[0]); 440 KURL locationURL(m_request->url(), locations[0]);
445 if (!locationURL.isValid()) { 441 if (!locationURL.isValid()) {
446 performNetworkError("Invalid Location header."); 442 performNetworkError("Invalid Location header.");
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 m_loaders.remove(loader); 907 m_loaders.remove(loader);
912 loader->dispose(); 908 loader->dispose();
913 } 909 }
914 910
915 DEFINE_TRACE(FetchManager) { 911 DEFINE_TRACE(FetchManager) {
916 visitor->trace(m_loaders); 912 visitor->trace(m_loaders);
917 ContextLifecycleObserver::trace(visitor); 913 ContextLifecycleObserver::trace(visitor);
918 } 914 }
919 915
920 } // namespace blink 916 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/fetch/Response.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698