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

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 2753453003: Reject unadvertised encodings (Closed)
Patch Set: Reject unadvertised encodings. Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "url/origin.h" 69 #include "url/origin.h"
70 70
71 #if defined(OS_ANDROID) 71 #if defined(OS_ANDROID)
72 #include "net/android/network_library.h" 72 #include "net/android/network_library.h"
73 #endif 73 #endif
74 74
75 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; 75 static const char kAvailDictionaryHeader[] = "Avail-Dictionary";
76 76
77 namespace { 77 namespace {
78 78
79 const char kDeflate[] = "deflate";
80 const char kGZip[] = "gzip";
81 const char kSdch[] = "sdch";
82 const char kXGZip[] = "x-gzip";
83 const char kBrotli[] = "br";
84
85 // True if the request method is "safe" (per section 4.2.1 of RFC 7231). 79 // True if the request method is "safe" (per section 4.2.1 of RFC 7231).
86 bool IsMethodSafe(const std::string& method) { 80 bool IsMethodSafe(const std::string& method) {
87 return method == "GET" || method == "HEAD" || method == "OPTIONS" || 81 return method == "GET" || method == "HEAD" || method == "OPTIONS" ||
88 method == "TRACE"; 82 method == "TRACE";
89 } 83 }
90 84
91 // Logs whether the CookieStore used for this request matches the 85 // Logs whether the CookieStore used for this request matches the
92 // ChannelIDService used when establishing the connection that this request is 86 // ChannelIDService used when establishing the connection that this request is
93 // sent over. This logging is only done for requests to accounts.google.com, and 87 // sent over. This logging is only done for requests to accounts.google.com, and
94 // only for requests where Channel ID was sent when establishing the connection. 88 // only for requests where Channel ID was sent when establishing the connection.
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 DCHECK(transaction_.get()); 1051 DCHECK(transaction_.get());
1058 if (!response_info_) 1052 if (!response_info_)
1059 return nullptr; 1053 return nullptr;
1060 1054
1061 std::unique_ptr<SourceStream> upstream = URLRequestJob::SetUpSourceStream(); 1055 std::unique_ptr<SourceStream> upstream = URLRequestJob::SetUpSourceStream();
1062 HttpResponseHeaders* headers = GetResponseHeaders(); 1056 HttpResponseHeaders* headers = GetResponseHeaders();
1063 std::string type; 1057 std::string type;
1064 std::vector<SourceStream::SourceType> types; 1058 std::vector<SourceStream::SourceType> types;
1065 size_t iter = 0; 1059 size_t iter = 0;
1066 while (headers->EnumerateHeader(&iter, "Content-Encoding", &type)) { 1060 while (headers->EnumerateHeader(&iter, "Content-Encoding", &type)) {
1067 if (base::LowerCaseEqualsASCII(type, kBrotli)) { 1061 SourceStream::SourceType source_type =
1068 types.push_back(SourceStream::TYPE_BROTLI); 1062 FilterSourceStream::ParseEncodingType(type);
1069 } else if (base::LowerCaseEqualsASCII(type, kDeflate)) { 1063 if (source_type == SourceStream::TYPE_SDCH &&
1070 types.push_back(SourceStream::TYPE_DEFLATE); 1064 !request()->context()->sdch_manager()) {
1071 } else if (base::LowerCaseEqualsASCII(type, kGZip) ||
1072 base::LowerCaseEqualsASCII(type, kXGZip)) {
1073 types.push_back(SourceStream::TYPE_GZIP);
1074 } else if (base::LowerCaseEqualsASCII(type, kSdch)) {
1075 // If SDCH support is not configured, pass through raw response. 1065 // If SDCH support is not configured, pass through raw response.
1076 if (!request()->context()->sdch_manager()) 1066 return upstream;
1067 }
1068 switch (source_type) {
1069 case SourceStream::TYPE_BROTLI:
1070 case SourceStream::TYPE_DEFLATE:
1071 case SourceStream::TYPE_GZIP:
1072 case SourceStream::TYPE_SDCH:
1073 types.push_back(source_type);
1074 break;
1075 default:
1076 // Unknown encoding type. Pass through raw response body.
1077 return upstream; 1077 return upstream;
1078 types.push_back(SourceStream::TYPE_SDCH);
1079 } else {
1080 // Unknown encoding type. Pass through raw response body.
1081 return upstream;
1082 } 1078 }
1083 } 1079 }
1084 1080
1085 // Sdch specific hacks: 1081 // Sdch specific hacks:
1086 std::string mime_type; 1082 std::string mime_type;
1087 bool success = GetMimeType(&mime_type); 1083 bool success = GetMimeType(&mime_type);
1088 DCHECK(success || mime_type.empty()); 1084 DCHECK(success || mime_type.empty());
1089 SdchPolicyDelegate::FixUpSdchContentEncodings( 1085 SdchPolicyDelegate::FixUpSdchContentEncodings(
1090 request()->net_log(), mime_type, dictionaries_advertised_.get(), &types); 1086 request()->net_log(), mime_type, dictionaries_advertised_.get(), &types);
1091 1087
(...skipping 20 matching lines...) Expand all
1112 } 1108 }
1113 break; 1109 break;
1114 } 1110 }
1115 case SourceStream::TYPE_GZIP: 1111 case SourceStream::TYPE_GZIP:
1116 case SourceStream::TYPE_DEFLATE: 1112 case SourceStream::TYPE_DEFLATE:
1117 case SourceStream::TYPE_GZIP_FALLBACK: 1113 case SourceStream::TYPE_GZIP_FALLBACK:
1118 downstream = GzipSourceStream::Create(std::move(upstream), type); 1114 downstream = GzipSourceStream::Create(std::move(upstream), type);
1119 break; 1115 break;
1120 case SourceStream::TYPE_NONE: 1116 case SourceStream::TYPE_NONE:
1121 case SourceStream::TYPE_INVALID: 1117 case SourceStream::TYPE_INVALID:
1118 case SourceStream::TYPE_UNKNOWN:
1122 case SourceStream::TYPE_MAX: 1119 case SourceStream::TYPE_MAX:
1123 NOTREACHED(); 1120 NOTREACHED();
1124 return nullptr; 1121 return nullptr;
1125 } 1122 }
1126 if (downstream == nullptr) 1123 if (downstream == nullptr)
1127 return nullptr; 1124 return nullptr;
1128 upstream = std::move(downstream); 1125 upstream = std::move(downstream);
1129 } 1126 }
1130 1127
1131 return upstream; 1128 return upstream;
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 awaiting_callback_ = false; 1548 awaiting_callback_ = false;
1552 1549
1553 // Notify NetworkQualityEstimator. 1550 // Notify NetworkQualityEstimator.
1554 NetworkQualityEstimator* network_quality_estimator = 1551 NetworkQualityEstimator* network_quality_estimator =
1555 request()->context()->network_quality_estimator(); 1552 request()->context()->network_quality_estimator();
1556 if (network_quality_estimator) 1553 if (network_quality_estimator)
1557 network_quality_estimator->NotifyURLRequestDestroyed(*request()); 1554 network_quality_estimator->NotifyURLRequestDestroyed(*request());
1558 } 1555 }
1559 1556
1560 } // namespace net 1557 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698