| 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 |
| 21 namespace { | 22 namespace { |
| 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)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // Only retry idempotent methods. | 79 // Only retry idempotent methods. |
| 79 if (!IsRequestIdempotent(request)) | 80 if (!IsRequestIdempotent(request)) |
| 80 return false; | 81 return false; |
| 81 | 82 |
| 82 OverrideResponseAsRedirect(request, | 83 OverrideResponseAsRedirect(request, |
| 83 original_response_headers, | 84 original_response_headers, |
| 84 override_response_headers); | 85 override_response_headers); |
| 85 return true; | 86 return true; |
| 86 } | 87 } |
| 87 | 88 |
| 88 | 89 void OnResolveProxyHandler(const GURL& url, int load_flags, |
| 90 net::ProxyInfo* result) { |
| 91 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 92 if ((load_flags & net::LOAD_BYPASS_DATA_REDUCTION_PROXY) && |
| 93 DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial() && |
| 94 !result->is_direct() && |
| 95 result->proxy_server().isDataReductionProxy()) { |
| 96 result->UseDirect(); |
| 97 } |
| 98 #endif |
| 99 } |
| 89 | 100 |
| 90 bool IsRequestIdempotent(const net::URLRequest* request) { | 101 bool IsRequestIdempotent(const net::URLRequest* request) { |
| 91 DCHECK(request); | 102 DCHECK(request); |
| 92 if (request->method() == "GET" || | 103 if (request->method() == "GET" || |
| 93 request->method() == "OPTIONS" || | 104 request->method() == "OPTIONS" || |
| 94 request->method() == "HEAD" || | 105 request->method() == "HEAD" || |
| 95 request->method() == "PUT" || | 106 request->method() == "PUT" || |
| 96 request->method() == "DELETE" || | 107 request->method() == "DELETE" || |
| 97 request->method() == "TRACE") | 108 request->method() == "TRACE") |
| 98 return true; | 109 return true; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 net::ProxyService* proxy_service = request->context()->proxy_service(); | 157 net::ProxyService* proxy_service = request->context()->proxy_service(); |
| 147 DCHECK(proxy_service); | 158 DCHECK(proxy_service); |
| 148 | 159 |
| 149 proxy_service->MarkProxiesAsBadUntil(proxy_info, | 160 proxy_service->MarkProxiesAsBadUntil(proxy_info, |
| 150 bypass_duration, | 161 bypass_duration, |
| 151 fallback, | 162 fallback, |
| 152 request->net_log()); | 163 request->net_log()); |
| 153 } | 164 } |
| 154 | 165 |
| 155 } // namespace data_reduction_proxy | 166 } // namespace data_reduction_proxy |
| OLD | NEW |