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_BROWSER_DATA_REDUCTION_PROXY_PROTOCOL_H_
6#define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PROTOCOL_H_
7
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"
11
12namespace base {
13class TimeDelta;
14}
15
16namespace net {
17class HttpResponseHeaders;
18class ProxyConfig;
19class ProxyInfo;
20class ProxyServer;
21class URLRequest;
22}
23
24class GURL;
25
26namespace data_reduction_proxy {
27
28class DataReductionProxyParams;
29
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).
34bool 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);
40
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|.
47void OnResolveProxyHandler(const GURL& url,
48                           int load_flags,
49                           const net::ProxyConfig& data_reduction_proxy_config,
50                           const net::ProxyRetryInfoMap& proxy_retry_info,
51                           const DataReductionProxyParams* params,
52                           net::ProxyInfo* result);
53
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.
56bool IsRequestIdempotent(const net::URLRequest* request);
57
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.
62void OverrideResponseAsRedirect(
63    net::URLRequest* request,
64    const net::HttpResponseHeaders* original_response_headers,
65    scoped_refptr<net::HttpResponseHeaders>* override_response_headers);
66
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.
71void MarkProxiesAsBadUntil(net::URLRequest* request,
72                           base::TimeDelta& bypass_duration,
73                           bool bypass_all,
74                           const std::pair<GURL, GURL>& data_reduction_proxies);
75
76}  // namespace data_reduction_proxy
77#endif  // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_PROTOCOL_H_
78