1 // Copyright 2018 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_HTTP_PROXY_FALLBACK_H_ 6 #define NET_HTTP_PROXY_FALLBACK_H_ 7 8 // ------------------------------------------------------------ 9 // Proxy Fallback Overview 10 // ------------------------------------------------------------ 11 // 12 // Proxy fallback is a feature that is split between the proxy resolution layer 13 // and the HTTP layers. 14 // 15 // The proxy resolution layer is responsible for: 16 // * Obtaining a list of proxies to use 17 // (ProxyResolutionService::ResolveProxy). Proxy lists are (usually) the 18 // result of having evaluated a PAC script, such as: 19 // return "PROXY foobar1:8080; HTTPS foobar2:8080; DIRECT"; 20 // 21 // * Re-ordering the proxy list such that proxy chains that have recently 22 // failed are given lower priority (ProxyInfo::DeprioritizeBadProxyChains) 23 // 24 // * Maintaining the expiring cache of proxy chains that have recently failed. 25 // 26 // 27 // The HTTP layer is responsible for: 28 // * Attempting to issue the URLRequest through each of the 29 // proxy chains, in the order specified by the list. 30 // 31 // * Deciding whether this attempt was successful, whether it was a failure 32 // but should keep trying other proxy chains, or whether it was a failure 33 // and should stop trying other proxy chains. 34 // 35 // * Upon successful completion of an attempt though a proxy chain, calling 36 // ProxyResolutionService::ReportSuccess to inform it of all the failed 37 // attempts that were made. (A proxy chain is only considered to be "bad" 38 // if the request was able to be completed through some other proxy chain). 39 // 40 // 41 // Exactly how to interpret the proxy lists returned by PAC is not specified by 42 // a standard. The justifications for what errors are considered for fallback 43 // are given beside the implementation. 44 45 #include "net/base/net_export.h" 46 47 namespace net { 48 49 class ProxyChain; 50 51 // Returns true if a failed request issued through a proxy chain should be 52 // re-tried using the next proxy chain in the fallback list. 53 // 54 // The proxy fallback logic is a compromise between compatibility and 55 // increasing odds of success, and may choose not to retry a request on the 56 // next proxy option, even though that could work. 57 // 58 // - `proxy_chain` is the proxy chain that failed the request. 59 // - `error` is the error for the request when it was sent through 60 // `proxy_chain`. 61 // - `final_error` is an out parameter that is set with the "final" error to 62 // report to the caller. The error is only re-written in cases where 63 // CanFalloverToNextProxy() returns false. 64 // - `is_for_ip_protection` is true if this request is to an IP Protection 65 // proxy. 66 NET_EXPORT bool CanFalloverToNextProxy(const ProxyChain& proxy_chain, 67 int error, 68 int* final_error, 69 bool is_for_ip_protection = false); 70 71 } // namespace net 72 73 #endif // NET_HTTP_PROXY_FALLBACK_H_ 74