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_COMMON_DATA_REDUCTION_PROXY_HEADERS_H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_COMMON_DATA_REDUCTION_PROXY_HEADERS_H_
10 #include "base/macros.h"
11 #include "base/time/time.h"
12 #include "net/proxy/proxy_service.h"
16 class HttpResponseHeaders
;
20 namespace data_reduction_proxy
{
22 // Contains instructions contained in the Chrome-Proxy header.
23 struct DataReductionProxyInfo
{
24 DataReductionProxyInfo() : bypass_all(false) {}
26 // True if Chrome should bypass all available data reduction proxies. False
27 // if only the currently connected data reduction proxy should be bypassed.
30 // Amount of time to bypass the data reduction proxy or proxies.
31 base::TimeDelta bypass_duration
;
34 // Returns true if the Chrome-Proxy header is present and contains a bypass
35 // delay. Sets |proxy_info->bypass_duration| to the specified delay if greater
36 // than 0, and to 0 otherwise to indicate that the default proxy delay
37 // (as specified in |ProxyList::UpdateRetryInfoOnFallback|) should be used.
38 // If all available data reduction proxies should by bypassed, |bypass_all| is
39 // set to true. |proxy_info| must be non-NULL.
40 bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders
* headers
,
41 DataReductionProxyInfo
* proxy_info
);
43 // Returns true if the response contains the data reduction proxy Via header
44 // value. If non-NULL, sets |has_intermediary| to true if another server added
45 // a Via header after the data reduction proxy, and to false otherwise. Used to
46 // check the integrity of data reduction proxy responses and whether there are
47 // other middleboxes between the data reduction proxy and the client.
48 bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders
* headers
,
49 bool* has_intermediary
);
51 // Returns the reason why the Chrome proxy should be bypassed or not, and
52 // populates |proxy_info| with information on how long to bypass if
54 net::ProxyService::DataReductionProxyBypassType
GetDataReductionProxyBypassType(
55 const net::HttpResponseHeaders
* headers
,
56 DataReductionProxyInfo
* proxy_info
);
58 // Searches for the specified Chrome-Proxy action, and if present saves its
59 // value as a string in |action_value|. Only returns the first one and ignores
60 // the rest if multiple actions match |action_prefix|.
61 bool GetDataReductionProxyActionValue(
62 const net::HttpResponseHeaders
* headers
,
63 const std::string
& action_prefix
,
64 std::string
* action_value
);
66 // Searches for the specified Chrome-Proxy action, and if present interprets
67 // its value as a duration in seconds.
68 bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders
* headers
,
69 const std::string
& action_prefix
,
70 base::TimeDelta
* bypass_duration
);
72 // Gets the fingerprint of the Chrome-Proxy header.
73 bool GetDataReductionProxyActionFingerprintChromeProxy(
74 const net::HttpResponseHeaders
* headers
,
75 std::string
* chrome_proxy_fingerprint
);
77 // Gets the fingerprint of the Via header.
78 bool GetDataReductionProxyActionFingerprintVia(
79 const net::HttpResponseHeaders
* headers
,
80 std::string
* via_fingerprint
);
82 // Gets the fingerprint of a list of headers.
83 bool GetDataReductionProxyActionFingerprintOtherHeaders(
84 const net::HttpResponseHeaders
* headers
,
85 std::string
* other_headers_fingerprint
);
87 // Gets the fingerprint of Content-Length header.
88 bool GetDataReductionProxyActionFingerprintContentLength(
89 const net::HttpResponseHeaders
* headers
,
90 std::string
* content_length_fingerprint
);
92 // Returns values of the Chrome-Proxy header, but with its fingerprint removed.
93 void GetDataReductionProxyHeaderWithFingerprintRemoved(
94 const net::HttpResponseHeaders
* headers
,
95 std::vector
<std::string
>* values
);
97 } // namespace data_reduction_proxy
98 #endif // COMPONENTS_DATA_REDUCTION_PROXY_COMMON_DATA_REDUCTION_PROXY_HEADERS_H_