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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PROTOCOL_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PROTOCOL_H_
8 #include "base/memory/ref_counted.h"
9 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h"
10 #include "net/proxy/proxy_retry_info.h"
17 class HttpResponseHeaders
;
26 namespace data_reduction_proxy
{
28 class DataReductionProxyParams
;
30 // Decides whether to mark the data reduction proxy as temporarily bad and
31 // put it on the proxy retry list. Returns true if the request should be
32 // retried. Sets |override_response_headers| to redirect if so. Returns
33 // the DataReductionProxyBypassType (if not NULL).
34 bool MaybeBypassProxyAndPrepareToRetry(
35 const DataReductionProxyParams
* params
,
36 net::URLRequest
* request
,
37 const net::HttpResponseHeaders
* original_response_headers
,
38 scoped_refptr
<net::HttpResponseHeaders
>* override_response_headers
,
39 DataReductionProxyBypassType
* proxy_bypass_type
);
41 // Configure |result| to proceed directly to the origin if |result|'s current
42 // proxy is the data reduction proxy, the
43 // |net::LOAD_BYPASS_DATA_REDUCTION_PROXY| |load_flag| is set, and the
44 // DataCompressionProxyCriticalBypass Finch trial is set.
45 // This handler is intended to be invoked only by
46 // |ChromeNetworkDelegate.NotifyResolveProxy|.
47 void OnResolveProxyHandler(const GURL
& url
,
49 const net::ProxyConfig
& data_reduction_proxy_config
,
50 const net::ProxyRetryInfoMap
& proxy_retry_info
,
51 const DataReductionProxyParams
* params
,
52 net::ProxyInfo
* result
);
54 // Returns true if the request method is idempotent. Only idempotent requests
55 // are retried on a bypass. Visible as part of the public API for testing.
56 bool IsRequestIdempotent(const net::URLRequest
* request
);
58 // Sets the override headers to contain a status line that indicates a
59 // redirect (a 302), a "Location:" header that points to the request url,
60 // and sets load flags to bypass proxies.
61 // Visible as part of the public API for testing.
62 void OverrideResponseAsRedirect(
63 net::URLRequest
* request
,
64 const net::HttpResponseHeaders
* original_response_headers
,
65 scoped_refptr
<net::HttpResponseHeaders
>* override_response_headers
);
67 // Adds non-empty entries in |data_reduction_proxies| to the retry map
68 // maintained by the proxy service of the request. Adds
69 // |data_reduction_proxies.second| to the retry list only if |bypass_all| is
70 // true. Visible as part of the public API for testing.
71 void MarkProxiesAsBadUntil(net::URLRequest
* request
,
72 base::TimeDelta
& bypass_duration
,
74 const std::pair
<GURL
, GURL
>& data_reduction_proxies
);
76 } // namespace data_reduction_proxy
77 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PROTOCOL_H_