Convert env to a defaultdict in run_executable() to fix other callers of that function.
[chromium-blink-merge.git] / components / data_reduction_proxy / common / data_reduction_proxy_headers.h
blob849ade037bc78d14892e100de782e86aea7f8137
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_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/time/time.h"
12 #include "net/proxy/proxy_service.h"
14 namespace net {
16 class HttpResponseHeaders;
18 } // namespace net
20 namespace data_reduction_proxy {
22 // Values of the UMA DataReductionProxy.BypassType{Primary|Fallback}
23 // and DataReductionProxy.BlockType{Primary|Fallback} histograms.
24 // This enum must remain synchronized with the enum of the same
25 // name in metrics/histograms/histograms.xml.
26 enum DataReductionProxyBypassType {
27 // Bypass due to explicit instruction for the current request.
28 BYPASS_EVENT_TYPE_CURRENT = 0,
30 // Bypass the proxy for less than one minute.
31 BYPASS_EVENT_TYPE_SHORT = 1,
33 // Bypass the proxy for one to five minutes.
34 BYPASS_EVENT_TYPE_MEDIUM = 2,
36 // Bypass the proxy for more than five minutes.
37 BYPASS_EVENT_TYPE_LONG = 3,
39 // Bypass due to a 4xx missing via header.
40 BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_4XX = 4,
42 // Bypass due to other missing via header, excluding 4xx errors.
43 BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_OTHER = 5,
45 // Bypass due to 407 response from proxy without a challenge.
46 BYPASS_EVENT_TYPE_MALFORMED_407 = 6,
48 // Bypass due to a 500 internal server error
49 BYPASS_EVENT_TYPE_STATUS_500_HTTP_INTERNAL_SERVER_ERROR = 7,
51 // Bypass because the request URI was too long.
52 BYPASS_EVENT_TYPE_STATUS_502_HTTP_BAD_GATEWAY = 8,
54 // Bypass due to a 503 response.
55 BYPASS_EVENT_TYPE_STATUS_503_HTTP_SERVICE_UNAVAILABLE = 9,
57 // Bypass due to any network error.
58 BYPASS_EVENT_TYPE_NETWORK_ERROR = 10,
60 // This must always be last.
61 BYPASS_EVENT_TYPE_MAX = 11
64 // Contains instructions contained in the Chrome-Proxy header.
65 struct DataReductionProxyInfo {
66 DataReductionProxyInfo()
67 : bypass_all(false), mark_proxies_as_bad(false) {}
69 // True if Chrome should bypass all available data reduction proxies. False
70 // if only the currently connected data reduction proxy should be bypassed.
71 bool bypass_all;
73 // True iff Chrome should mark the data reduction proxy or proxies as bad for
74 // the period of time specified in |bypass_duration|.
75 bool mark_proxies_as_bad;
77 // Amount of time to bypass the data reduction proxy or proxies. This value is
78 // ignored if |mark_proxies_as_bad| is false.
79 base::TimeDelta bypass_duration;
82 // Returns true if the Chrome-Proxy header is present and contains a bypass
83 // delay. Sets |proxy_info->bypass_duration| to the specified delay if greater
84 // than 0, and to 0 otherwise to indicate that the default proxy delay
85 // (as specified in |ProxyList::UpdateRetryInfoOnFallback|) should be used.
86 // If all available data reduction proxies should by bypassed, |bypass_all| is
87 // set to true. |proxy_info| must be non-NULL.
88 bool ParseHeadersAndSetProxyInfo(const net::HttpResponseHeaders* headers,
89 DataReductionProxyInfo* proxy_info);
91 // Returns true if the response contains the data reduction proxy Via header
92 // value. If non-NULL, sets |has_intermediary| to true if another server added
93 // a Via header after the data reduction proxy, and to false otherwise. Used to
94 // check the integrity of data reduction proxy responses and whether there are
95 // other middleboxes between the data reduction proxy and the client.
96 bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers,
97 bool* has_intermediary);
99 // Returns the reason why the Chrome proxy should be bypassed or not, and
100 // populates |proxy_info| with information on how long to bypass if
101 // applicable.
102 DataReductionProxyBypassType GetDataReductionProxyBypassType(
103 const net::HttpResponseHeaders* headers,
104 DataReductionProxyInfo* proxy_info);
106 // Searches for the specified Chrome-Proxy action, and if present saves its
107 // value as a string in |action_value|. Only returns the first one and ignores
108 // the rest if multiple actions match |action_prefix|.
109 bool GetDataReductionProxyActionValue(
110 const net::HttpResponseHeaders* headers,
111 const std::string& action_prefix,
112 std::string* action_value);
114 // Searches for the specified Chrome-Proxy action, and if present interprets
115 // its value as a duration in seconds.
116 bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders* headers,
117 const std::string& action_prefix,
118 base::TimeDelta* bypass_duration);
120 // Gets the fingerprint of the Chrome-Proxy header.
121 bool GetDataReductionProxyActionFingerprintChromeProxy(
122 const net::HttpResponseHeaders* headers,
123 std::string* chrome_proxy_fingerprint);
125 // Gets the fingerprint of the Via header.
126 bool GetDataReductionProxyActionFingerprintVia(
127 const net::HttpResponseHeaders* headers,
128 std::string* via_fingerprint);
130 // Gets the fingerprint of a list of headers.
131 bool GetDataReductionProxyActionFingerprintOtherHeaders(
132 const net::HttpResponseHeaders* headers,
133 std::string* other_headers_fingerprint);
135 // Gets the fingerprint of Content-Length header.
136 bool GetDataReductionProxyActionFingerprintContentLength(
137 const net::HttpResponseHeaders* headers,
138 std::string* content_length_fingerprint);
140 // Returns values of the Chrome-Proxy header, but with its fingerprint removed.
141 void GetDataReductionProxyHeaderWithFingerprintRemoved(
142 const net::HttpResponseHeaders* headers,
143 std::vector<std::string>* values);
145 } // namespace data_reduction_proxy
146 #endif // COMPONENTS_DATA_REDUCTION_PROXY_COMMON_DATA_REDUCTION_PROXY_HEADERS_H_