Class ProxyHandler

  • All Implemented Interfaces:
    HttpHandler

    public final class ProxyHandler
    extends Object
    implements HttpHandler
    An HTTP handler which proxies content to a remote server.

    This handler acts like a filter. The ProxyClient has a chance to decide if it knows how to proxy the request. If it does then it will provide a connection that can used to connect to the remote server, otherwise the next handler will be invoked and the request will proceed as normal.

    Author:
    David M. Lloyd
    • Field Detail

      • UTF_8

        public static final String UTF_8
    • Constructor Detail

      • ProxyHandler

        public ProxyHandler​(ProxyClient proxyClient,
                            int maxRequestTime,
                            HttpHandler next,
                            boolean rewriteHostHeader,
                            boolean reuseXForwarded)
        Parameters:
        proxyClient - the client to use to make the proxy call
        maxRequestTime - the maximum amount of time to allow the request to be processed
        next - the next handler in line
        rewriteHostHeader - should the HOST header be rewritten to use the target host of the call.
        reuseXForwarded - should any existing X-Forwarded-For header be used or should it be overwritten.
      • ProxyHandler

        public ProxyHandler​(ProxyClient proxyClient,
                            int maxRequestTime,
                            HttpHandler next,
                            boolean rewriteHostHeader,
                            boolean reuseXForwarded,
                            int maxConnectionRetries)
        Parameters:
        proxyClient - the client to use to make the proxy call
        maxRequestTime - the maximum amount of time to allow the request to be processed
        next - the next handler in line
        rewriteHostHeader - should the HOST header be rewritten to use the target host of the call.
        reuseXForwarded - should any existing X-Forwarded-For header be used or should it be overwritten.
        maxConnectionRetries -
    • Method Detail

      • addRequestHeader

        public ProxyHandler addRequestHeader​(HttpString header,
                                             ExchangeAttribute attribute)
        Adds a request header to the outgoing request. If the header resolves to null or an empty string it will not be added, however any existing header with the same name will be removed.
        Parameters:
        header - The header name
        attribute - The header value attribute.
        Returns:
        this
      • addRequestHeader

        public ProxyHandler addRequestHeader​(HttpString header,
                                             String value)
        Adds a request header to the outgoing request. If the header resolves to null or an empty string it will not be added, however any existing header with the same name will be removed.
        Parameters:
        header - The header name
        value - The header value attribute.
        Returns:
        this
      • addRequestHeader

        public ProxyHandler addRequestHeader​(HttpString header,
                                             String attribute,
                                             ClassLoader classLoader)
        Adds a request header to the outgoing request. If the header resolves to null or an empty string it will not be added, however any existing header with the same name will be removed.

        The attribute value will be parsed, and the resulting exchange attribute will be used to create the actual header value.

        Parameters:
        header - The header name
        attribute - The header value attribute.
        Returns:
        this
      • removeRequestHeader

        public ProxyHandler removeRequestHeader​(HttpString header)
        Removes a request header
        Parameters:
        header - the header
        Returns:
        this
      • getMaxConnectionRetries

        public int getMaxConnectionRetries()