public class ProxyHandler extends AbstractHttpHandler
The HttpTunnel mechanism is also used to implement the CONNECT method.
Modifier and Type | Field and Description |
---|---|
protected HashSet |
_allowedConnectPorts
Set of allowed CONNECT ports.
|
protected StringMap |
_DontProxyHeaders
Map of leg by leg headers (not end to end).
|
protected StringMap |
_ProxyAuthHeaders
Map of leg by leg headers (not end to end).
|
protected Set |
_proxyHostsBlackList |
protected Set |
_proxyHostsWhiteList |
protected StringMap |
_ProxySchemes
Map of allows schemes to proxy Should be a set, but more efficient string map is used
instead.
|
protected int |
_tunnelTimeoutMs |
Constructor and Description |
---|
ProxyHandler() |
Modifier and Type | Method and Description |
---|---|
protected void |
customizeConnection(String pathInContext,
String pathParams,
HttpRequest request,
Socket socket)
Customize proxy Socket connection for CONNECT.
|
protected void |
customizeConnection(String pathInContext,
String pathParams,
HttpRequest request,
URLConnection connection)
Customize proxy URL connection.
|
String[] |
getProxyHostsBlackList()
Get proxy host black list.
|
String[] |
getProxyHostsWhiteList()
Get proxy host white list.
|
int |
getTunnelTimeoutMs() |
void |
handle(String pathInContext,
String pathParams,
HttpRequest request,
HttpResponse response)
Handle a request.
|
void |
handleConnect(String pathInContext,
String pathParams,
HttpRequest request,
HttpResponse response) |
boolean |
isAnonymous() |
protected boolean |
isForbidden(String scheme,
String host,
int port,
boolean openNonPrivPorts)
Is scheme,host & port Forbidden.
|
protected boolean |
isForbidden(URI uri)
Is URL Forbidden.
|
protected URL |
isProxied(URI uri)
Is URL Proxied.
|
protected HttpTunnel |
newHttpTunnel(HttpRequest request,
HttpResponse response,
InetAddress iaddr,
int port,
int timeoutMS) |
protected void |
sendForbid(HttpRequest request,
HttpResponse response,
URI uri)
Send Forbidden.
|
void |
setAnonymous(boolean anonymous) |
void |
setProxyHostsBlackList(String[] hosts)
Set proxy host black list.
|
void |
setProxyHostsWhiteList(String[] hosts)
Set proxy host white list.
|
void |
setTunnelTimeoutMs(int ms)
Tunnel timeout.
|
void |
start()
Start the LifeCycle.
|
getHttpContext, getName, handleTrace, initialize, isStarted, setName, stop, toString
protected Set _proxyHostsWhiteList
protected Set _proxyHostsBlackList
protected int _tunnelTimeoutMs
protected StringMap _DontProxyHeaders
protected StringMap _ProxyAuthHeaders
protected StringMap _ProxySchemes
protected HashSet _allowedConnectPorts
public void start() throws Exception
LifeCycle
start
in interface LifeCycle
start
in class AbstractHttpHandler
Exception
- An arbitrary exception may be thrown.public String[] getProxyHostsWhiteList()
public void setProxyHostsWhiteList(String[] hosts)
hosts
- Array of hostnames and IPs that are proxied, or null if all hosts are proxied.public String[] getProxyHostsBlackList()
public void setProxyHostsBlackList(String[] hosts)
hosts
- Array of hostnames and IPs that are NOT proxied.public int getTunnelTimeoutMs()
public void setTunnelTimeoutMs(int ms)
public void handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException
HttpHandler
pathInContext
- The context pathpathParams
- Path parameters such as encoded Session IDrequest
- The HttpRequest requestresponse
- The HttpResponse responseHttpException
IOException
public void handleConnect(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws HttpException, IOException
HttpException
IOException
protected HttpTunnel newHttpTunnel(HttpRequest request, HttpResponse response, InetAddress iaddr, int port, int timeoutMS) throws IOException
IOException
protected void customizeConnection(String pathInContext, String pathParams, HttpRequest request, Socket socket) throws IOException
IOException
protected void customizeConnection(String pathInContext, String pathParams, HttpRequest request, URLConnection connection) throws IOException
IOException
protected URL isProxied(URI uri) throws MalformedURLException
uri
- The requested URI, which should include a scheme, host and port.MalformedURLException
protected boolean isForbidden(URI uri)
protected boolean isForbidden(String scheme, String host, int port, boolean openNonPrivPorts)
scheme
- A scheme that mast be in the proxySchemes StringMap.host
- A host that must pass the white and black listsport
- A port that must in the allowedConnectPorts SetopenNonPrivPorts
- If true ports greater than 1024 are allowed.protected void sendForbid(HttpRequest request, HttpResponse response, URI uri) throws IOException
IOException
public boolean isAnonymous()
public void setAnonymous(boolean anonymous)
anonymous
- The anonymous to set.Copyright © 2013. All Rights Reserved.