• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors
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 NET_BASE_PROXY_DELEGATE_H_
6 #define NET_BASE_PROXY_DELEGATE_H_
7 
8 #include <string>
9 
10 #include "net/base/net_errors.h"
11 #include "net/base/net_export.h"
12 #include "net/proxy_resolution/proxy_retry_info.h"
13 
14 class GURL;
15 
16 namespace net {
17 
18 class HttpRequestHeaders;
19 class HttpResponseHeaders;
20 class ProxyInfo;
21 class ProxyServer;
22 
23 // Delegate for setting up a connection.
24 class NET_EXPORT ProxyDelegate {
25  public:
26   ProxyDelegate() = default;
27   ProxyDelegate(const ProxyDelegate&) = delete;
28   ProxyDelegate& operator=(const ProxyDelegate&) = delete;
29   virtual ~ProxyDelegate() = default;
30 
31   // Called as the proxy is being resolved for |url| for a |method| request.
32   // The caller may pass an empty string to get method agnostic resoulution.
33   // Allows the delegate to override the proxy resolution decision made by
34   // ProxyResolutionService. The delegate may override the decision by modifying
35   // the ProxyInfo |result|.
36   virtual void OnResolveProxy(const GURL& url,
37                               const std::string& method,
38                               const ProxyRetryInfoMap& proxy_retry_info,
39                               ProxyInfo* result) = 0;
40 
41   // Called when use of |bad_proxy| fails due to |net_error|. |net_error| is
42   // the network error encountered, if any, and OK if the fallback was
43   // for a reason other than a network error (e.g. the proxy service was
44   // explicitly directed to skip a proxy).
45   virtual void OnFallback(const ProxyServer& bad_proxy, int net_error) = 0;
46 
47   // Called immediately before a proxy tunnel request is sent. Provides the
48   // embedder an opportunity to add extra request headers.
49   virtual void OnBeforeTunnelRequest(const ProxyServer& proxy_server,
50                                      HttpRequestHeaders* extra_headers) = 0;
51 
52   // Called when the response headers for the proxy tunnel request have been
53   // received. Allows the delegate to override the net error code of the tunnel
54   // request. Returning OK causes the standard tunnel response handling to be
55   // performed. Implementations should make sure they can trust |proxy_server|
56   // before making decisions based on |response_headers|.
57   virtual Error OnTunnelHeadersReceived(
58       const ProxyServer& proxy_server,
59       const HttpResponseHeaders& response_headers) = 0;
60 };
61 
62 }  // namespace net
63 
64 #endif  // NET_BASE_PROXY_DELEGATE_H_
65