Chromium Code Reviews| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 #include "net/url_request/http_user_agent_settings.h" | 60 #include "net/url_request/http_user_agent_settings.h" |
| 61 #include "net/url_request/url_request.h" | 61 #include "net/url_request/url_request.h" |
| 62 #include "net/url_request/url_request_context.h" | 62 #include "net/url_request/url_request_context.h" |
| 63 #include "net/url_request/url_request_error_job.h" | 63 #include "net/url_request/url_request_error_job.h" |
| 64 #include "net/url_request/url_request_job_factory.h" | 64 #include "net/url_request/url_request_job_factory.h" |
| 65 #include "net/url_request/url_request_redirect_job.h" | 65 #include "net/url_request/url_request_redirect_job.h" |
| 66 #include "net/url_request/url_request_throttler_manager.h" | 66 #include "net/url_request/url_request_throttler_manager.h" |
| 67 #include "net/websockets/websocket_handshake_stream_base.h" | 67 #include "net/websockets/websocket_handshake_stream_base.h" |
| 68 #include "url/origin.h" | 68 #include "url/origin.h" |
| 69 | 69 |
| 70 #if defined(OS_ANDROID) | |
| 71 #include "net/android/network_library.h" | |
| 72 #endif | |
| 73 | |
| 70 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; | 74 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; |
| 71 | 75 |
| 72 namespace { | 76 namespace { |
| 73 | 77 |
| 74 const char kDeflate[] = "deflate"; | 78 const char kDeflate[] = "deflate"; |
| 75 const char kGZip[] = "gzip"; | 79 const char kGZip[] = "gzip"; |
| 76 const char kSdch[] = "sdch"; | 80 const char kSdch[] = "sdch"; |
| 77 const char kXGZip[] = "x-gzip"; | 81 const char kXGZip[] = "x-gzip"; |
| 78 const char kBrotli[] = "br"; | 82 const char kBrotli[] = "br"; |
| 79 | 83 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 params->channel_id_service->GetUniqueID()) { | 165 params->channel_id_service->GetUniqueID()) { |
| 162 ephemerality = PERSISTENT_MATCH; | 166 ephemerality = PERSISTENT_MATCH; |
| 163 } else { | 167 } else { |
| 164 NOTREACHED(); | 168 NOTREACHED(); |
| 165 ephemerality = PERSISTENT_MISMATCH; | 169 ephemerality = PERSISTENT_MISMATCH; |
| 166 } | 170 } |
| 167 UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.StoreEphemerality", ephemerality, | 171 UMA_HISTOGRAM_ENUMERATION("Net.TokenBinding.StoreEphemerality", ephemerality, |
| 168 EPHEMERALITY_MAX); | 172 EPHEMERALITY_MAX); |
| 169 } | 173 } |
| 170 | 174 |
| 171 net::URLRequestRedirectJob* MaybeInternallyRedirect( | |
| 172 net::URLRequest* request, | |
| 173 net::NetworkDelegate* network_delegate) { | |
| 174 const GURL& url = request->url(); | |
| 175 if (url.SchemeIsCryptographic()) | |
| 176 return nullptr; | |
| 177 | |
| 178 net::TransportSecurityState* hsts = | |
| 179 request->context()->transport_security_state(); | |
| 180 if (!hsts || !hsts->ShouldUpgradeToSSL(url.host())) | |
| 181 return nullptr; | |
| 182 | |
| 183 GURL::Replacements replacements; | |
| 184 replacements.SetSchemeStr(url.SchemeIs(url::kHttpScheme) ? url::kHttpsScheme | |
| 185 : url::kWssScheme); | |
| 186 return new net::URLRequestRedirectJob( | |
| 187 request, network_delegate, url.ReplaceComponents(replacements), | |
| 188 // Use status code 307 to preserve the method, so POST requests work. | |
| 189 net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS"); | |
| 190 } | |
| 191 | |
| 192 } // namespace | 175 } // namespace |
| 193 | 176 |
| 194 namespace net { | 177 namespace net { |
| 195 | 178 |
| 196 // TODO(darin): make sure the port blocking code is not lost | 179 // TODO(darin): make sure the port blocking code is not lost |
| 197 // static | 180 // static |
| 198 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, | 181 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, |
| 199 NetworkDelegate* network_delegate, | 182 NetworkDelegate* network_delegate, |
| 200 const std::string& scheme) { | 183 const std::string& scheme) { |
| 201 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || | 184 DCHECK(scheme == "http" || scheme == "https" || scheme == "ws" || |
| 202 scheme == "wss"); | 185 scheme == "wss"); |
| 203 | 186 |
| 204 if (!request->context()->http_transaction_factory()) { | 187 if (!request->context()->http_transaction_factory()) { |
| 205 NOTREACHED() << "requires a valid context"; | 188 NOTREACHED() << "requires a valid context"; |
| 206 return new URLRequestErrorJob( | 189 return new URLRequestErrorJob( |
| 207 request, network_delegate, ERR_INVALID_ARGUMENT); | 190 request, network_delegate, ERR_INVALID_ARGUMENT); |
| 208 } | 191 } |
| 209 | 192 |
| 210 URLRequestRedirectJob* redirect = | 193 const GURL& url = request->url(); |
| 211 MaybeInternallyRedirect(request, network_delegate); | 194 |
| 212 if (redirect) | 195 // Check for reasons not to return a URLRequestHttpJob. These don't apply to |
| 213 return redirect; | 196 // https and wss requests. |
| 197 if (!url.SchemeIsCryptographic()) { | |
| 198 // Check for HSTS upgrade. | |
| 199 net::TransportSecurityState* hsts = | |
| 200 request->context()->transport_security_state(); | |
| 201 if (hsts && hsts->ShouldUpgradeToSSL(url.host())) { | |
| 202 GURL::Replacements replacements; | |
| 203 replacements.SetSchemeStr( | |
| 204 url.SchemeIs(url::kHttpScheme) ? url::kHttpsScheme : url::kWssScheme); | |
| 205 return new net::URLRequestRedirectJob( | |
| 206 request, network_delegate, url.ReplaceComponents(replacements), | |
| 207 // Use status code 307 to preserve the method, so POST requests work. | |
| 208 net::URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "HSTS"); | |
| 209 } | |
| 210 | |
| 211 #if defined(OS_ANDROID) | |
| 212 // Check whether the app allows cleartext traffic to this host, and return | |
| 213 // ERR_BLOCKED_BY_CLIENT if not. | |
| 214 if (request->context()->check_cleartext_permitted() && | |
| 215 !net::android::IsCleartextPermitted(url.host())) { | |
| 216 return new net::URLRequestErrorJob(request, network_delegate, | |
| 217 net::ERR_BLOCKED_BY_CLIENT); | |
|
mmenke
2016/12/13 19:04:56
May want to add another error code for this. ERR_
mgersh
2016/12/13 19:34:42
Done.
| |
| 218 } | |
| 219 #endif | |
| 220 } | |
| 214 | 221 |
| 215 return new URLRequestHttpJob(request, | 222 return new URLRequestHttpJob(request, |
| 216 network_delegate, | 223 network_delegate, |
| 217 request->context()->http_user_agent_settings()); | 224 request->context()->http_user_agent_settings()); |
| 218 } | 225 } |
| 219 | 226 |
| 220 URLRequestHttpJob::URLRequestHttpJob( | 227 URLRequestHttpJob::URLRequestHttpJob( |
| 221 URLRequest* request, | 228 URLRequest* request, |
| 222 NetworkDelegate* network_delegate, | 229 NetworkDelegate* network_delegate, |
| 223 const HttpUserAgentSettings* http_user_agent_settings) | 230 const HttpUserAgentSettings* http_user_agent_settings) |
| (...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1541 awaiting_callback_ = false; | 1548 awaiting_callback_ = false; |
| 1542 | 1549 |
| 1543 // Notify NetworkQualityEstimator. | 1550 // Notify NetworkQualityEstimator. |
| 1544 NetworkQualityEstimator* network_quality_estimator = | 1551 NetworkQualityEstimator* network_quality_estimator = |
| 1545 request()->context()->network_quality_estimator(); | 1552 request()->context()->network_quality_estimator(); |
| 1546 if (network_quality_estimator) | 1553 if (network_quality_estimator) |
| 1547 network_quality_estimator->NotifyURLRequestDestroyed(*request()); | 1554 network_quality_estimator->NotifyURLRequestDestroyed(*request()); |
| 1548 } | 1555 } |
| 1549 | 1556 |
| 1550 } // namespace net | 1557 } // namespace net |
| OLD | NEW |