Package org.microproxy
Class UpstreamProxyManager
java.lang.Object
org.microproxy.UpstreamProxyManager
- All Implemented Interfaces:
ChainedProxyManager
A
ChainedProxyManager configured like command-line HTTP clients: an upstream proxy URL
for plain HTTP, one for HTTPS (CONNECT), and NoProxyRules for hosts reached directly.
Proxy URLs take the forms http://[user:password@]host[:port], https://...
(TLS to the proxy itself), h2://... (TLS, offering HTTP/2 with ALPN), h2c://...
(HTTP/2 with prior knowledge over plain TCP), socks4://..., socks4a://...,
socks5://... and socks5h://.... An HTTP/2 proxy carries tunnels and plain-HTTP
requests as streams of shared connections (ChainedProxy.http2()); an h2:// proxy
that chooses HTTP/1.1 is spoken to in HTTP/1.1. SOCKS proxies always receive host names, so the
a/h variants behave like the plain ones. Default ports are 80 (http, h2c), 443
(https, h2) and 1080 (SOCKS).
bootstrap.withChainProxyManager(UpstreamProxyManager.fromEnvironment(System.getenv()));
bootstrap.withChainProxyManager(new UpstreamProxyManager(
"http://user:secret@proxy.corp:3128", null, NoProxyRules.parse("localhost,.corp,10.0.0.0/8")));
-
Constructor Summary
ConstructorsConstructorDescriptionUpstreamProxyManager(String httpProxyUrl, String httpsProxyUrl, NoProxyRules noProxy) Creates upstream routing with protocol-specific proxies and bypass rules. -
Method Summary
Modifier and TypeMethodDescriptionstatic UpstreamProxyManagerfromEnvironment(Map<String, String> env) Readshttp_proxy,https_proxy/HTTPS_PROXY,all_proxy/ALL_PROXYandno_proxy/NO_PROXY, like curl.voidlookupChainedProxies(HttpRequest request, Queue<ChainedProxy> chainedProxies, ClientDetails clientDetails) Adds the proxies to try, in order, tochainedProxies.static ChainedProxyParses a proxy URL into aChainedProxy.toString()Returns the upstream proxies, their credentials masked (http://***@host:port), and whether direct is a fallback.booleanReturns whether any of the upstream proxies is spoken to in HTTP/2 (h2://orh2c://).withFallbackToDirect(boolean fallbackToDirect) Also try a direct connection when the upstream proxy cannot be reached.
-
Constructor Details
-
UpstreamProxyManager
Creates upstream routing with protocol-specific proxies and bypass rules.- Parameters:
httpProxyUrl- proxy for plain HTTP requests, ornullfor directhttpsProxyUrl- proxy for CONNECT / HTTPS, ornullto usehttpProxyUrlnoProxy- the rules identifying destinations that bypass upstream proxies
-
-
Method Details
-
fromEnvironment
Readshttp_proxy,https_proxy/HTTPS_PROXY,all_proxy/ALL_PROXYandno_proxy/NO_PROXY, like curl. Upper-caseHTTP_PROXYis ignored, as curl does, because CGI servers set it from the request'sProxyheader.- Parameters:
env- the environment variable map- Returns:
- the manager, or
nullwhen no proxy variable is set
-
withFallbackToDirect
Also try a direct connection when the upstream proxy cannot be reached.- Parameters:
fallbackToDirect- whether to try connecting directly after upstream proxy failure- Returns:
- this manager
-
lookupChainedProxies
public void lookupChainedProxies(HttpRequest request, Queue<ChainedProxy> chainedProxies, ClientDetails clientDetails) Description copied from interface:ChainedProxyManagerAdds the proxies to try, in order, tochainedProxies. Leave the queue empty to reject the request with502, or addChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTIONto connect directly.- Specified by:
lookupChainedProxiesin interfaceChainedProxyManager- Parameters:
request- the request headchainedProxies- the queue to populate with proxies to try, in orderclientDetails- the client address and authentication details
-
usesHttp2
public boolean usesHttp2()Returns whether any of the upstream proxies is spoken to in HTTP/2 (h2://orh2c://).- Returns:
- whether any of the upstream proxies is spoken to in HTTP/2 (
h2://orh2c://)
-
toString
Returns the upstream proxies, their credentials masked (http://***@host:port), and whether direct is a fallback. -
proxy
Parses a proxy URL into aChainedProxy.- Parameters:
url- the upstream proxy URL- Returns:
- the parsed upstream proxy
-