Class DefaultHttpProxyServer

    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • TRAFFIC_SHAPING_CHECK_INTERVAL_MS

        private static final long TRAFFIC_SHAPING_CHECK_INTERVAL_MS
        The interval in ms at which the GlobalTrafficShapingHandler will run to compute and throttle the proxy-to-server bandwidth.
        See Also:
        Constant Field Values
      • MAX_INITIAL_LINE_LENGTH_DEFAULT

        private static final int MAX_INITIAL_LINE_LENGTH_DEFAULT
        See Also:
        Constant Field Values
      • MAX_HEADER_SIZE_DEFAULT

        private static final int MAX_HEADER_SIZE_DEFAULT
        See Also:
        Constant Field Values
      • MAX_CHUNK_SIZE_DEFAULT

        private static final int MAX_CHUNK_SIZE_DEFAULT
        See Also:
        Constant Field Values
      • FALLBACK_PROXY_ALIAS

        private static final String FALLBACK_PROXY_ALIAS
        The proxy alias to use in the Via header if no explicit proxy alias is specified and the hostname of the local machine cannot be resolved.
        See Also:
        Constant Field Values
      • serverGroup

        private final ServerGroup serverGroup
        Our ServerGroup. Multiple proxy servers can share the same ServerGroup in order to reuse threads and other such resources.
      • authenticateSslClients

        private final boolean authenticateSslClients
      • transparent

        private final boolean transparent
      • connectTimeout

        private volatile int connectTimeout
      • idleConnectionTimeout

        private volatile int idleConnectionTimeout
      • maxInitialLineLength

        private final int maxInitialLineLength
      • maxHeaderSize

        private final int maxHeaderSize
      • maxChunkSize

        private final int maxChunkSize
      • allowRequestsToOriginServer

        private final boolean allowRequestsToOriginServer
      • acceptProxyProtocol

        private final boolean acceptProxyProtocol
      • sendProxyProtocol

        private final boolean sendProxyProtocol
      • proxyAlias

        private final String proxyAlias
        The alias or pseudonym for this proxy, used when adding the Via header.
      • activityTrackers

        private final Collection<ActivityTracker> activityTrackers
        Track all ActivityTrackers for tracking proxying activity.
      • allChannels

        private final ChannelGroup allChannels
        Keep track of all channels created by this proxy server for later shutdown when the proxy is stopped.
      • jvmShutdownHook

        private final Thread jvmShutdownHook
        JVM shutdown hook to shutdown this proxy server. Declared as a class-level variable to allow removing the shutdown hook when the proxy server is stopped normally.
    • Constructor Detail

      • DefaultHttpProxyServer

        private DefaultHttpProxyServer​(ServerGroup serverGroup,
                                       TransportProtocol transportProtocol,
                                       InetSocketAddress requestedAddress,
                                       SslEngineSource sslEngineSource,
                                       boolean authenticateSslClients,
                                       ProxyAuthenticator proxyAuthenticator,
                                       ChainedProxyManager chainProxyManager,
                                       MitmManager mitmManager,
                                       HttpFiltersSource filtersSource,
                                       boolean transparent,
                                       int idleConnectionTimeout,
                                       Collection<ActivityTracker> activityTrackers,
                                       int connectTimeout,
                                       HostResolver serverResolver,
                                       long readThrottleBytesPerSecond,
                                       long writeThrottleBytesPerSecond,
                                       InetSocketAddress localAddress,
                                       String proxyAlias,
                                       int maxInitialLineLength,
                                       int maxHeaderSize,
                                       int maxChunkSize,
                                       boolean allowRequestsToOriginServer,
                                       boolean acceptProxyProtocol,
                                       boolean sendProxyProtocol)
        Creates a new proxy server.
        Parameters:
        serverGroup - our ServerGroup for shared thread pools and such
        transportProtocol - The protocol to use for data transport
        requestedAddress - The address on which this server will listen
        sslEngineSource - (optional) if specified, this Proxy will encrypt inbound connections from clients using an SSLEngine obtained from this SslEngineSource.
        authenticateSslClients - Indicate whether or not to authenticate clients when using SSL
        proxyAuthenticator - (optional) If specified, requests to the proxy will be authenticated using HTTP BASIC authentication per the provided ProxyAuthenticator
        chainProxyManager - The proxy to send requests to if chaining proxies. Typically null.
        mitmManager - The MitmManager to use for man in the middle'ing CONNECT requests
        filtersSource - Source for HttpFilters
        transparent - If true, this proxy will run as a transparent proxy. This will not modify the response, and will only modify the request to amend the URI if the target is the origin server (to comply with RFC 7230 section 5.3.1).
        idleConnectionTimeout - The timeout (in seconds) for auto-closing idle connections.
        activityTrackers - for tracking activity on this proxy
        connectTimeout - number of milliseconds to wait to connect to the upstream server
        serverResolver - the HostResolver to use for resolving server addresses
        readThrottleBytesPerSecond - read throttle bandwidth
        writeThrottleBytesPerSecond - write throttle bandwidth
        maxInitialLineLength -
        maxHeaderSize -
        maxChunkSize -
        allowRequestsToOriginServer - when true, allow the proxy to handle requests that contain an origin-form URI, as defined in RFC 7230 5.3.1
        acceptProxyProtocol - when true, the proxy will accept a proxy protocol header from client
        sendProxyProtocol - when true, the proxy will send a proxy protocol header to the server
    • Method Detail

      • createGlobalTrafficShapingHandler

        private GlobalTrafficShapingHandler createGlobalTrafficShapingHandler​(TransportProtocol transportProtocol,
                                                                              long readThrottleBytesPerSecond,
                                                                              long writeThrottleBytesPerSecond)
        Creates a new GlobalTrafficShapingHandler for this HttpProxyServer, using this proxy's proxyToServerEventLoop.
      • isTransparent

        boolean isTransparent()
      • getConnectTimeout

        public int getConnectTimeout()
        Description copied from interface: HttpProxyServer
        Returns the maximum time to wait, in milliseconds, to connect to a server.
        Specified by:
        getConnectTimeout in interface HttpProxyServer
      • setConnectTimeout

        public void setConnectTimeout​(int connectTimeoutMs)
        Description copied from interface: HttpProxyServer
        Sets the maximum time to wait, in milliseconds, to connect to a server.
        Specified by:
        setConnectTimeout in interface HttpProxyServer
      • getServerResolver

        public HostResolver getServerResolver()
      • setThrottle

        public void setThrottle​(long readThrottleBytesPerSecond,
                                long writeThrottleBytesPerSecond)
        Description copied from interface: HttpProxyServer

        Set the read/write throttle bandwidths (in bytes/second) for this proxy.

        Specified by:
        setThrottle in interface HttpProxyServer
      • getReadThrottle

        public long getReadThrottle()
      • getWriteThrottle

        public long getWriteThrottle()
      • getMaxInitialLineLength

        public int getMaxInitialLineLength()
      • getMaxHeaderSize

        public int getMaxHeaderSize()
      • getMaxChunkSize

        public int getMaxChunkSize()
      • isAllowRequestsToOriginServer

        public boolean isAllowRequestsToOriginServer()
      • isAcceptProxyProtocol

        public boolean isAcceptProxyProtocol()
      • isSendProxyProtocol

        public boolean isSendProxyProtocol()
      • clone

        public HttpProxyServerBootstrap clone()
        Description copied from interface: HttpProxyServer

        Clone the existing server, with a port 1 higher and everything else the same. If the proxy was started with port 0 (JVM-assigned port), the cloned proxy will also use a JVM-assigned port.

        The new server will share event loops with the original server. The event loops will use whatever name was given to the first server in the clone group. The server group will not terminate until the original server and all clones terminate.

        Specified by:
        clone in interface HttpProxyServer
        Overrides:
        clone in class Object
        Returns:
        a bootstrap that allows customizing and starting the cloned server
      • stop

        public void stop()
        Description copied from interface: HttpProxyServer
        Stops the server and all related clones. Waits for traffic to stop before shutting down.
        Specified by:
        stop in interface HttpProxyServer
      • abort

        public void abort()
        Description copied from interface: HttpProxyServer
        Stops the server and all related clones immediately, without waiting for traffic to stop.
        Specified by:
        abort in interface HttpProxyServer
      • doStop

        protected void doStop​(boolean graceful)
        Performs cleanup necessary to stop the server. Closes all channels opened by the server and unregisters this server from the server group.
        Parameters:
        graceful - when true, waits for requests to terminate before stopping the server
      • registerChannel

        protected void registerChannel​(Channel channel)
        Register a new Channel with this server, for later closing.
      • unregisterChannel

        protected void unregisterChannel​(Channel channel)
      • closeAllChannels

        protected void closeAllChannels​(boolean graceful)
        Closes all channels opened by this proxy server.
        Parameters:
        graceful - when false, attempts to shutdown all channels immediately and ignores any channel-closing exceptions
      • doStart

        private void doStart()
      • getMitmManager

        protected MitmManager getMitmManager()
      • getProxyAlias

        public String getProxyAlias()