| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 case SourceStream::TYPE_NONE: |
| 1076 // Identity encoding type. Pass through raw response body. |
| 1077 return upstream; | 1077 return upstream; |
| 1078 types.push_back(SourceStream::TYPE_SDCH); | 1078 default: |
| 1079 } else { | 1079 // Unknown encoding type. Pass through raw response body. |
| 1080 // Unknown encoding type. Pass through raw response body. | 1080 // Despite of reporting to UMA, request will not be canceled; though |
| 1081 return upstream; | 1081 // it is expected that user will see malformed / garbage response. |
| 1082 FilterSourceStream::ReportContentDecodingFailed( |
| 1083 FilterSourceStream::TYPE_UNKNOWN); |
| 1084 return upstream; |
| 1082 } | 1085 } |
| 1083 } | 1086 } |
| 1084 | 1087 |
| 1085 // Sdch specific hacks: | 1088 // Sdch specific hacks: |
| 1086 std::string mime_type; | 1089 std::string mime_type; |
| 1087 bool success = GetMimeType(&mime_type); | 1090 bool success = GetMimeType(&mime_type); |
| 1088 DCHECK(success || mime_type.empty()); | 1091 DCHECK(success || mime_type.empty()); |
| 1089 SdchPolicyDelegate::FixUpSdchContentEncodings( | 1092 SdchPolicyDelegate::FixUpSdchContentEncodings( |
| 1090 request()->net_log(), mime_type, dictionaries_advertised_.get(), &types); | 1093 request()->net_log(), mime_type, dictionaries_advertised_.get(), &types); |
| 1091 | 1094 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1112 } | 1115 } |
| 1113 break; | 1116 break; |
| 1114 } | 1117 } |
| 1115 case SourceStream::TYPE_GZIP: | 1118 case SourceStream::TYPE_GZIP: |
| 1116 case SourceStream::TYPE_DEFLATE: | 1119 case SourceStream::TYPE_DEFLATE: |
| 1117 case SourceStream::TYPE_GZIP_FALLBACK: | 1120 case SourceStream::TYPE_GZIP_FALLBACK: |
| 1118 downstream = GzipSourceStream::Create(std::move(upstream), type); | 1121 downstream = GzipSourceStream::Create(std::move(upstream), type); |
| 1119 break; | 1122 break; |
| 1120 case SourceStream::TYPE_NONE: | 1123 case SourceStream::TYPE_NONE: |
| 1121 case SourceStream::TYPE_INVALID: | 1124 case SourceStream::TYPE_INVALID: |
| 1125 case SourceStream::TYPE_REJECTED: |
| 1126 case SourceStream::TYPE_UNKNOWN: |
| 1122 case SourceStream::TYPE_MAX: | 1127 case SourceStream::TYPE_MAX: |
| 1123 NOTREACHED(); | 1128 NOTREACHED(); |
| 1124 return nullptr; | 1129 return nullptr; |
| 1125 } | 1130 } |
| 1126 if (downstream == nullptr) | 1131 if (downstream == nullptr) |
| 1127 return nullptr; | 1132 return nullptr; |
| 1128 upstream = std::move(downstream); | 1133 upstream = std::move(downstream); |
| 1129 } | 1134 } |
| 1130 | 1135 |
| 1131 return upstream; | 1136 return upstream; |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 awaiting_callback_ = false; | 1556 awaiting_callback_ = false; |
| 1552 | 1557 |
| 1553 // Notify NetworkQualityEstimator. | 1558 // Notify NetworkQualityEstimator. |
| 1554 NetworkQualityEstimator* network_quality_estimator = | 1559 NetworkQualityEstimator* network_quality_estimator = |
| 1555 request()->context()->network_quality_estimator(); | 1560 request()->context()->network_quality_estimator(); |
| 1556 if (network_quality_estimator) | 1561 if (network_quality_estimator) |
| 1557 network_quality_estimator->NotifyURLRequestDestroyed(*request()); | 1562 network_quality_estimator->NotifyURLRequestDestroyed(*request()); |
| 1558 } | 1563 } |
| 1559 | 1564 |
| 1560 } // namespace net | 1565 } // namespace net |
| OLD | NEW |