org.openqa.selenium.server
Class ProxyHandler

java.lang.Object
  extended by org.openqa.jetty.http.handler.AbstractHttpHandler
      extended by org.openqa.selenium.server.ProxyHandler
All Implemented Interfaces:
Serializable, HttpHandler, LifeCycle

public class ProxyHandler
extends AbstractHttpHandler

Proxy request handler. A HTTP/1.1 Proxy. This implementation uses the JVMs URL implementation to make proxy requests.

The HttpTunnel mechanism is also used to implement the CONNECT method.

Version:
$Id: ProxyHandler.java,v 1.34 2005/10/05 13:32:59 gregwilkins Exp $
Author:
Greg Wilkins (gregw), [email protected] (chained proxy)
See Also:
Serialized Form

Nested Class Summary
static class ProxyHandler.SslRelay
           
 
Field Summary
protected  HashSet<Integer> _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<String> _proxyHostsBlackList
           
protected  Set<String> _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 Summary
ProxyHandler(boolean trustAllSSLCertificates, String dontInjectRegex, String debugURL, boolean proxyInjectionMode, boolean forceProxyChain, int port, Object shutdownLock)
           
 
Method Summary
 void generateSSLCertsForLoggingHosts(HttpServer server)
           
protected  ProxyHandler.SslRelay getSslRelayOrCreateNew(URI uri, String serverHost, Integer serverPort, HttpServer server)
           
 void handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response)
          Handle a request.
 void handleConnect(HttpRequest request, HttpResponse response)
           
protected  boolean isForbidden(String scheme, String host)
          Is scheme,host & port Forbidden.
protected  boolean isForbidden(URI uri)
          Is URL Forbidden.
protected  URL isProxied(URI uri)
          Is URL Proxied.
protected  HttpTunnel newHttpTunnel(HttpResponse response, InetAddress iaddr, int port, int timeoutMS)
           
protected  long proxyPlainTextRequest(URL url, HttpRequest request, HttpResponse response)
           
protected  void sendForbid(HttpResponse response)
          Send Forbidden.
protected  void sendNotFound(HttpResponse response)
          Send not found.
 boolean shouldInject(String path)
           
 void start()
          Start the LifeCycle.
protected  void wireUpSslWithCyberVilliansCA(String host, ProxyHandler.SslRelay listener)
           
 
Methods inherited from class org.openqa.jetty.http.handler.AbstractHttpHandler
getHttpContext, getName, handleTrace, initialize, isStarted, setName, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_proxyHostsWhiteList

protected Set<String> _proxyHostsWhiteList

_proxyHostsBlackList

protected Set<String> _proxyHostsBlackList

_tunnelTimeoutMs

protected int _tunnelTimeoutMs

_DontProxyHeaders

protected StringMap _DontProxyHeaders
Map of leg by leg headers (not end to end). Should be a set, but more efficient string map is used instead.


_ProxyAuthHeaders

protected StringMap _ProxyAuthHeaders
Map of leg by leg headers (not end to end). Should be a set, but more efficient string map is used instead.


_ProxySchemes

protected StringMap _ProxySchemes
Map of allows schemes to proxy Should be a set, but more efficient string map is used instead.


_allowedConnectPorts

protected HashSet<Integer> _allowedConnectPorts
Set of allowed CONNECT ports.

Constructor Detail

ProxyHandler

public ProxyHandler(boolean trustAllSSLCertificates,
                    String dontInjectRegex,
                    String debugURL,
                    boolean proxyInjectionMode,
                    boolean forceProxyChain,
                    int port,
                    Object shutdownLock)
Method Detail

start

public void start()
           throws Exception
Description copied from interface: LifeCycle
Start the LifeCycle.

Specified by:
start in interface LifeCycle
Overrides:
start in class AbstractHttpHandler
Throws:
Exception - An arbitrary exception may be thrown.

handle

public void handle(String pathInContext,
                   String pathParams,
                   HttpRequest request,
                   HttpResponse response)
            throws IOException
Description copied from interface: HttpHandler
Handle a request. Note that Handlers are tried in order until one has handled the request. i.e. until request.isHandled() returns true. In broad terms this means, either a response has been commited or request.setHandled(true) has been called.

Parameters:
pathInContext - The context path
pathParams - Path parameters such as encoded Session ID
request - The HttpRequest request
response - The HttpResponse response
Throws:
IOException

proxyPlainTextRequest

protected long proxyPlainTextRequest(URL url,
                                     HttpRequest request,
                                     HttpResponse response)
                              throws IOException
Throws:
IOException

shouldInject

public boolean shouldInject(String path)

generateSSLCertsForLoggingHosts

public void generateSSLCertsForLoggingHosts(HttpServer server)

handleConnect

public void handleConnect(HttpRequest request,
                          HttpResponse response)
                   throws IOException
Throws:
IOException

getSslRelayOrCreateNew

protected ProxyHandler.SslRelay getSslRelayOrCreateNew(URI uri,
                                                       String serverHost,
                                                       Integer serverPort,
                                                       HttpServer server)
                                                throws Exception
Throws:
Exception

wireUpSslWithCyberVilliansCA

protected void wireUpSslWithCyberVilliansCA(String host,
                                            ProxyHandler.SslRelay listener)

newHttpTunnel

protected HttpTunnel newHttpTunnel(HttpResponse response,
                                   InetAddress iaddr,
                                   int port,
                                   int timeoutMS)
                            throws IOException
Throws:
IOException

isProxied

protected URL isProxied(URI uri)
                 throws MalformedURLException
Is URL Proxied. Method to allow derived handlers to select which URIs are proxied and to where.

Parameters:
uri - The requested URI, which should include a scheme, host and port.
Returns:
The URL to proxy to, or null if the passed URI should not be proxied. The default implementation returns the passed uri if isForbidden() returns true.
Throws:
MalformedURLException

isForbidden

protected boolean isForbidden(URI uri)
Is URL Forbidden.

Returns:
True if the URL is not forbidden. Calls isForbidden(scheme,host,port,true);

isForbidden

protected boolean isForbidden(String scheme,
                              String host)
Is scheme,host & port Forbidden.

Parameters:
scheme - A scheme that mast be in the proxySchemes StringMap.
host - A host that must pass the white and black lists
Returns:
True if the request to the scheme,host and port is not forbidden.

sendForbid

protected void sendForbid(HttpResponse response)
                   throws IOException
Send Forbidden. Method called to send forbidden response. Default implementation calls sendError(403)

Throws:
IOException

sendNotFound

protected void sendNotFound(HttpResponse response)
                     throws IOException
Send not found. Method called to send not found response. Default implementation calls sendError(404)

Throws:
IOException


Copyright © 2013. All Rights Reserved.