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/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" | 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" |
15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
16 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 16 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
17 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 17 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
18 #include "crypto/random.h" | 18 #include "crypto/random.h" |
| 19 #include "net/base/host_port_pair.h" |
19 #include "net/proxy/proxy_server.h" | 20 #include "net/proxy/proxy_server.h" |
20 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 namespace data_reduction_proxy { | 24 namespace data_reduction_proxy { |
24 | 25 |
25 // The empty version for the authentication protocol. Currently used by | 26 // The empty version for the authentication protocol. Currently used by |
26 // Android webview. | 27 // Android webview. |
27 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
28 const char kAndroidWebViewProtocolVersion[] = "0"; | 29 const char kAndroidWebViewProtocolVersion[] = "0"; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 crypto::RandBytes(output, length); | 84 crypto::RandBytes(output, length); |
84 } | 85 } |
85 | 86 |
86 void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader( | 87 void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader( |
87 net::URLRequest* request, | 88 net::URLRequest* request, |
88 const net::ProxyServer& proxy_server, | 89 const net::ProxyServer& proxy_server, |
89 net::HttpRequestHeaders* request_headers) { | 90 net::HttpRequestHeaders* request_headers) { |
90 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 91 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
91 if (!proxy_server.is_valid()) | 92 if (!proxy_server.is_valid()) |
92 return; | 93 return; |
93 if (data_reduction_proxy_params_ && | 94 if (proxy_server.is_direct()) |
94 data_reduction_proxy_params_->IsDataReductionProxy( | 95 return; |
95 proxy_server.host_port_pair(), NULL)) { | 96 MaybeAddRequestHeaderImpl(proxy_server.host_port_pair(), |
96 AddAuthorizationHeader(request_headers); | 97 false, |
97 } | 98 request_headers); |
| 99 } |
| 100 |
| 101 void DataReductionProxyAuthRequestHandler::MaybeAddProxyTunnelRequestHandler( |
| 102 const net::HostPortPair& proxy_server, |
| 103 net::HttpRequestHeaders* request_headers) { |
| 104 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 105 MaybeAddRequestHeaderImpl(proxy_server, true, request_headers); |
98 } | 106 } |
99 | 107 |
100 void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader( | 108 void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader( |
101 net::HttpRequestHeaders* headers) { | 109 net::HttpRequestHeaders* headers) { |
102 base::Time now = Now(); | 110 base::Time now = Now(); |
103 if (now - last_update_time_ > base::TimeDelta::FromHours(24)) { | 111 if (now - last_update_time_ > base::TimeDelta::FromHours(24)) { |
104 last_update_time_ = now; | 112 last_update_time_ = now; |
105 ComputeCredentials(last_update_time_, &session_, &credentials_); | 113 ComputeCredentials(last_update_time_, &session_, &credentials_); |
106 } | 114 } |
107 const char kChromeProxyHeader[] = "Chrome-Proxy"; | 115 const char kChromeProxyHeader[] = "Chrome-Proxy"; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 174 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
167 std::string key = | 175 std::string key = |
168 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); | 176 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); |
169 #if defined(SPDY_PROXY_AUTH_VALUE) | 177 #if defined(SPDY_PROXY_AUTH_VALUE) |
170 if (key.empty()) | 178 if (key.empty()) |
171 key = SPDY_PROXY_AUTH_VALUE; | 179 key = SPDY_PROXY_AUTH_VALUE; |
172 #endif | 180 #endif |
173 return key; | 181 return key; |
174 } | 182 } |
175 | 183 |
| 184 void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeaderImpl( |
| 185 const net::HostPortPair& proxy_server, |
| 186 bool expect_ssl, |
| 187 net::HttpRequestHeaders* request_headers) { |
| 188 if (proxy_server.IsEmpty()) |
| 189 return; |
| 190 if (data_reduction_proxy_params_ && |
| 191 data_reduction_proxy_params_->IsDataReductionProxy(proxy_server, NULL) && |
| 192 net::HostPortPair::FromURL( |
| 193 data_reduction_proxy_params_->ssl_origin()).Equals( |
| 194 proxy_server) == expect_ssl) { |
| 195 AddAuthorizationHeader(request_headers); |
| 196 } |
| 197 } |
| 198 |
176 } // namespace data_reduction_proxy | 199 } // namespace data_reduction_proxy |
OLD | NEW |