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_protocol.
h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 9 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
10 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 10 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
11 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
12 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
13 #include "net/proxy/proxy_info.h" | 13 #include "net/proxy/proxy_info.h" |
14 #include "net/proxy/proxy_list.h" | 14 #include "net/proxy/proxy_list.h" |
15 #include "net/proxy/proxy_server.h" | 15 #include "net/proxy/proxy_server.h" |
16 #include "net/proxy/proxy_service.h" | 16 #include "net/proxy/proxy_service.h" |
17 #include "net/url_request/url_request.h" | 17 #include "net/url_request/url_request.h" |
18 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace { | 21 namespace { |
| 22 |
22 bool SetProxyServerFromGURL(const GURL& gurl, | 23 bool SetProxyServerFromGURL(const GURL& gurl, |
23 net::ProxyServer* proxy_server) { | 24 net::ProxyServer* proxy_server) { |
24 DCHECK(proxy_server); | 25 DCHECK(proxy_server); |
25 if (!gurl.SchemeIsHTTPOrHTTPS()) | 26 if (!gurl.SchemeIsHTTPOrHTTPS()) |
26 return false; | 27 return false; |
27 *proxy_server = net::ProxyServer(gurl.SchemeIs("http") ? | 28 *proxy_server = net::ProxyServer(gurl.SchemeIs("http") ? |
28 net::ProxyServer::SCHEME_HTTP : | 29 net::ProxyServer::SCHEME_HTTP : |
29 net::ProxyServer::SCHEME_HTTPS, | 30 net::ProxyServer::SCHEME_HTTPS, |
30 net::HostPortPair::FromURL(gurl)); | 31 net::HostPortPair::FromURL(gurl)); |
31 return true; | 32 return true; |
32 } | 33 } |
| 34 |
33 } // namespace | 35 } // namespace |
34 | 36 |
35 namespace data_reduction_proxy { | 37 namespace data_reduction_proxy { |
36 | 38 |
37 bool MaybeBypassProxyAndPrepareToRetry( | 39 bool MaybeBypassProxyAndPrepareToRetry( |
38 const DataReductionProxyParams* data_reduction_proxy_params, | 40 const DataReductionProxyParams* data_reduction_proxy_params, |
39 net::URLRequest* request, | 41 net::URLRequest* request, |
40 const net::HttpResponseHeaders* original_response_headers, | 42 const net::HttpResponseHeaders* original_response_headers, |
41 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { | 43 scoped_refptr<net::HttpResponseHeaders>* override_response_headers) { |
42 if (!data_reduction_proxy_params) | 44 if (!data_reduction_proxy_params) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Only retry idempotent methods. | 83 // Only retry idempotent methods. |
82 if (!IsRequestIdempotent(request)) | 84 if (!IsRequestIdempotent(request)) |
83 return false; | 85 return false; |
84 | 86 |
85 OverrideResponseAsRedirect(request, | 87 OverrideResponseAsRedirect(request, |
86 original_response_headers, | 88 original_response_headers, |
87 override_response_headers); | 89 override_response_headers); |
88 return true; | 90 return true; |
89 } | 91 } |
90 | 92 |
91 | 93 void OnResolveProxyHandler(const GURL& url, |
| 94 int load_flags, |
| 95 const DataReductionProxyParams* params, |
| 96 net::ProxyInfo* result) { |
| 97 if ((load_flags & net::LOAD_BYPASS_DATA_REDUCTION_PROXY) && |
| 98 DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial() && |
| 99 !result->is_empty() && |
| 100 !result->is_direct() && |
| 101 params && |
| 102 params->IsDataReductionProxy( |
| 103 result->proxy_server().host_port_pair(), NULL)) { |
| 104 result->UseDirect(); |
| 105 } |
| 106 } |
92 | 107 |
93 bool IsRequestIdempotent(const net::URLRequest* request) { | 108 bool IsRequestIdempotent(const net::URLRequest* request) { |
94 DCHECK(request); | 109 DCHECK(request); |
95 if (request->method() == "GET" || | 110 if (request->method() == "GET" || |
96 request->method() == "OPTIONS" || | 111 request->method() == "OPTIONS" || |
97 request->method() == "HEAD" || | 112 request->method() == "HEAD" || |
98 request->method() == "PUT" || | 113 request->method() == "PUT" || |
99 request->method() == "DELETE" || | 114 request->method() == "DELETE" || |
100 request->method() == "TRACE") | 115 request->method() == "TRACE") |
101 return true; | 116 return true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 net::ProxyService* proxy_service = request->context()->proxy_service(); | 164 net::ProxyService* proxy_service = request->context()->proxy_service(); |
150 DCHECK(proxy_service); | 165 DCHECK(proxy_service); |
151 | 166 |
152 proxy_service->MarkProxiesAsBadUntil(proxy_info, | 167 proxy_service->MarkProxiesAsBadUntil(proxy_info, |
153 bypass_duration, | 168 bypass_duration, |
154 fallback, | 169 fallback, |
155 request->net_log()); | 170 request->net_log()); |
156 } | 171 } |
157 | 172 |
158 } // namespace data_reduction_proxy | 173 } // namespace data_reduction_proxy |
OLD | NEW |