Home | History | Annotate | Download | only in common
      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.
      4 
      5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_COMMON_DATA_REDUCTION_PROXY_HEADERS_H_
      6 #define COMPONENTS_DATA_REDUCTION_PROXY_COMMON_DATA_REDUCTION_PROXY_HEADERS_H_
      7 
      8 #include <string>
      9 
     10 #include "base/macros.h"
     11 #include "base/time/time.h"
     12 #include "net/http/http_response_headers.h"
     13 #include "net/proxy/proxy_service.h"
     14 
     15 namespace data_reduction_proxy {
     16 
     17 // Contains instructions contained in the Chrome-Proxy header.
     18 struct DataReductionProxyInfo {
     19   DataReductionProxyInfo() : bypass_all(false) {}
     20 
     21   // True if Chrome should bypass all available data reduction proxies. False
     22   // if only the currently connected data reduction proxy should be bypassed.
     23   bool bypass_all;
     24 
     25   // Amount of time to bypass the data reduction proxy or proxies.
     26   base::TimeDelta bypass_duration;
     27 };
     28 
     29 // Returns true if the Chrome-Proxy header is present and contains a bypass
     30 // delay. Sets |proxy_info->bypass_duration| to the specified delay if greater
     31 // than 0, and to 0 otherwise to indicate that the default proxy delay
     32 // (as specified in |ProxyList::UpdateRetryInfoOnFallback|) should be used.
     33 // If all available data reduction proxies should by bypassed, |bypass_all| is
     34 // set to true. |proxy_info| must be non-NULL.
     35 bool GetDataReductionProxyInfo(
     36     const net::HttpResponseHeaders* headers,
     37     DataReductionProxyInfo* proxy_info);
     38 
     39 // Returns true if the response contain the data reduction proxy Via header
     40 // value. Used to check the integrity of data reduction proxy responses.
     41 bool HasDataReductionProxyViaHeader(const net::HttpResponseHeaders* headers);
     42 
     43 // Returns the reason why the Chrome proxy should be bypassed or not, and
     44 // populates |proxy_info| with information on how long to bypass if
     45 // applicable.
     46 net::ProxyService::DataReductionProxyBypassEventType
     47 GetDataReductionProxyBypassEventType(
     48     const net::HttpResponseHeaders* headers,
     49     DataReductionProxyInfo* proxy_info);
     50 
     51 // Searches for the specified Chrome-Proxy action, and if present interprets
     52 // its value as a duration in seconds.
     53 bool GetDataReductionProxyBypassDuration(
     54     const net::HttpResponseHeaders* headers,
     55     const std::string& action_prefix,
     56     base::TimeDelta* duration);
     57 
     58 }  // namespace data_reduction_proxy
     59 #endif  // COMPONENTS_DATA_REDUCTION_PROXY_COMMON_DATA_REDUCTION_PROXY_HEADERS_H_
     60