| OLD | NEW |
| 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 "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ
est_handler.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ
est_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| 15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" | 15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" |
| 16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
| 17 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 17 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
| 18 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 18 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
| 19 #include "crypto/random.h" | 19 #include "crypto/random.h" |
| 20 #include "net/base/host_port_pair.h" |
| 20 #include "net/proxy/proxy_server.h" | 21 #include "net/proxy/proxy_server.h" |
| 21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 | 24 |
| 24 namespace data_reduction_proxy { | 25 namespace data_reduction_proxy { |
| 25 | 26 |
| 26 // The empty version for the authentication protocol. Currently used by | 27 // The empty version for the authentication protocol. Currently used by |
| 27 // Android webview. | 28 // Android webview. |
| 28 #if defined(OS_ANDROID) | 29 #if defined(OS_ANDROID) |
| 29 const char kAndroidWebViewProtocolVersion[] = ""; | 30 const char kAndroidWebViewProtocolVersion[] = ""; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 crypto::RandBytes(output, length); | 97 crypto::RandBytes(output, length); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader( | 100 void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader( |
| 100 net::URLRequest* request, | 101 net::URLRequest* request, |
| 101 const net::ProxyServer& proxy_server, | 102 const net::ProxyServer& proxy_server, |
| 102 net::HttpRequestHeaders* request_headers) { | 103 net::HttpRequestHeaders* request_headers) { |
| 103 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 104 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 104 if (!proxy_server.is_valid()) | 105 if (!proxy_server.is_valid()) |
| 105 return; | 106 return; |
| 106 if (data_reduction_proxy_params_ && | 107 if (proxy_server.is_direct()) |
| 107 data_reduction_proxy_params_->IsDataReductionProxy( | 108 return; |
| 108 proxy_server.host_port_pair(), NULL)) { | 109 MaybeAddRequestHeaderImpl(proxy_server.host_port_pair(), |
| 109 AddAuthorizationHeader(request_headers); | 110 false, |
| 110 } | 111 request_headers); |
| 112 } |
| 113 |
| 114 void DataReductionProxyAuthRequestHandler::MaybeAddProxyTunnelRequestHandler( |
| 115 const net::HostPortPair& proxy_server, |
| 116 net::HttpRequestHeaders* request_headers) { |
| 117 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 118 MaybeAddRequestHeaderImpl(proxy_server, true, request_headers); |
| 111 } | 119 } |
| 112 | 120 |
| 113 void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader( | 121 void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader( |
| 114 net::HttpRequestHeaders* headers) { | 122 net::HttpRequestHeaders* headers) { |
| 115 base::Time now = Now(); | 123 base::Time now = Now(); |
| 116 if (now - last_update_time_ > base::TimeDelta::FromHours(24)) { | 124 if (now - last_update_time_ > base::TimeDelta::FromHours(24)) { |
| 117 last_update_time_ = now; | 125 last_update_time_ = now; |
| 118 ComputeCredentials(last_update_time_, &session_, &credentials_); | 126 ComputeCredentials(last_update_time_, &session_, &credentials_); |
| 119 } | 127 } |
| 120 const char kChromeProxyHeader[] = "Chrome-Proxy"; | 128 const char kChromeProxyHeader[] = "Chrome-Proxy"; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 189 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 182 std::string key = | 190 std::string key = |
| 183 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); | 191 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); |
| 184 #if defined(SPDY_PROXY_AUTH_VALUE) | 192 #if defined(SPDY_PROXY_AUTH_VALUE) |
| 185 if (key.empty()) | 193 if (key.empty()) |
| 186 key = SPDY_PROXY_AUTH_VALUE; | 194 key = SPDY_PROXY_AUTH_VALUE; |
| 187 #endif | 195 #endif |
| 188 return key; | 196 return key; |
| 189 } | 197 } |
| 190 | 198 |
| 199 void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeaderImpl( |
| 200 const net::HostPortPair& proxy_server, |
| 201 bool expect_ssl, |
| 202 net::HttpRequestHeaders* request_headers) { |
| 203 if (proxy_server.IsEmpty()) |
| 204 return; |
| 205 if (data_reduction_proxy_params_ && |
| 206 data_reduction_proxy_params_->IsDataReductionProxy(proxy_server, NULL) && |
| 207 net::HostPortPair::FromURL( |
| 208 data_reduction_proxy_params_->ssl_origin()).Equals( |
| 209 proxy_server) == expect_ssl) { |
| 210 AddAuthorizationHeader(request_headers); |
| 211 } |
| 212 } |
| 213 |
| 191 } // namespace data_reduction_proxy | 214 } // namespace data_reduction_proxy |
| OLD | NEW |