org.littleshoot.proxy.HttpProxyServerBootstrap Maven / Gradle / Ivy
Show all versions of littleproxy Show documentation
package org.littleshoot.proxy;
import org.littleshoot.proxy.impl.ThreadPoolConfiguration;
import java.net.InetSocketAddress;
/**
* Configures and starts an {@link HttpProxyServer}. The HttpProxyServer is
* built using {@link #start()}. Sensible defaults are available for all
* parameters such that {@link #start()} could be called immediately if you
* wish.
*/
public interface HttpProxyServerBootstrap {
/**
*
* Give the server a name (used for naming threads, useful for logging).
*
*
*
* Default = LittleProxy
*
*
* @param name
* @return
*/
HttpProxyServerBootstrap withName(String name);
/**
*
* Specify the {@link TransportProtocol} to use for incoming connections.
*
*
*
* Default = TCP
*
*
* @param transportProtocol
* @return
*/
HttpProxyServerBootstrap withTransportProtocol(
TransportProtocol transportProtocol);
/**
*
* Listen for incoming connections on the given address.
*
*
*
* Default = [bound ip]:8080
*
*
* @param address
* @return
*/
HttpProxyServerBootstrap withAddress(InetSocketAddress address);
/**
*
* Listen for incoming connections on the given port.
*
*
*
* Default = 8080
*
*
* @param port
* @return
*/
HttpProxyServerBootstrap withPort(int port);
/**
*
* Specify whether or not to only allow local connections.
*
*
*
* Default = true
*
*
* @param allowLocalOnly
* @return
*/
HttpProxyServerBootstrap withAllowLocalOnly(boolean allowLocalOnly);
/**
* This method has no effect and will be removed in a future release.
* @deprecated use {@link #withNetworkInterface(InetSocketAddress)} to avoid listening on all local addresses
*/
@Deprecated
HttpProxyServerBootstrap withListenOnAllAddresses(boolean listenOnAllAddresses);
/**
*
* Specify an {@link SslEngineSource} to use for encrypting inbound
* connections. Enabling this will enable SSL client authentication
* by default (see {@link #withAuthenticateSslClients(boolean)})
*
*
*
* Default = null
*
*
*
* Note - This and {@link #withManInTheMiddle(MitmManager)} are
* mutually exclusive.
*
*
* @param sslEngineSource
* @return
*/
HttpProxyServerBootstrap withSslEngineSource(
SslEngineSource sslEngineSource);
/**
*
* Specify whether or not to authenticate inbound SSL clients (only applies
* if {@link #withSslEngineSource(SslEngineSource)} has been set).
*
*
*
* Default = true
*
*
* @param authenticateSslClients
* @return
*/
HttpProxyServerBootstrap withAuthenticateSslClients(
boolean authenticateSslClients);
/**
*
* Specify a {@link ProxyAuthenticator} to use for doing basic HTTP
* authentication of clients.
*
*
*
* Default = null
*
*
* @param proxyAuthenticator
* @return
*/
HttpProxyServerBootstrap withProxyAuthenticator(
ProxyAuthenticator proxyAuthenticator);
/**
*
* Specify a {@link ChainedProxyManager} to use for chaining requests to
* another proxy.
*
*
*
* Default = null
*
*
* @param chainProxyManager
* @return
*/
HttpProxyServerBootstrap withChainProxyManager(
ChainedProxyManager chainProxyManager);
/**
*
* Specify an {@link MitmManager} to use for making this proxy act as an SSL
* man in the middle
*
*
*
* Default = null
*
*
*
* Note - This and {@link #withSslEngineSource(SslEngineSource)} are
* mutually exclusive.
*
*
* @param mitmManager
* @return
*/
HttpProxyServerBootstrap withManInTheMiddle(
MitmManager mitmManager);
/**
*
* Specify a {@link HttpFiltersSource} to use for filtering requests and/or
* responses through this proxy.
*
*
*
* Default = null
*
*
* @param filtersSource
* @return
*/
HttpProxyServerBootstrap withFiltersSource(
HttpFiltersSource filtersSource);
/**
*
* Specify whether or not to use secure DNS lookups for outbound
* connections.
*
*
*
* Default = false
*
*
* @param useDnsSec
* @return
*/
HttpProxyServerBootstrap withUseDnsSec(
boolean useDnsSec);
/**
*
* Specify whether or not to run this proxy as a transparent proxy.
*
*
*
* Default = false
*
*
* @param transparent
* @return
*/
HttpProxyServerBootstrap withTransparent(
boolean transparent);
/**
*
* Specify the timeout after which to disconnect idle connections, in
* seconds.
*
*
*
* Default = 70
*
*
* @param idleConnectionTimeout
* @return
*/
HttpProxyServerBootstrap withIdleConnectionTimeout(
int idleConnectionTimeout);
/**
*
* Specify the timeout for connecting to the upstream server on a new
* connection, in milliseconds.
*
*
*
* Default = 40000
*
*
* @param connectTimeout
* @return
*/
HttpProxyServerBootstrap withConnectTimeout(
int connectTimeout);
/**
* Specify a custom {@link HostResolver} for resolving server addresses.
*
* @param resolver
* @return
*/
HttpProxyServerBootstrap withServerResolver(HostResolver serverResolver);
/**
*
* Add an {@link ActivityTracker} for tracking activity in this proxy.
*
*
* @param activityTracker
* @return
*/
HttpProxyServerBootstrap plusActivityTracker(ActivityTracker activityTracker);
/**
*
* Specify the read and/or write bandwidth throttles for this proxy server. 0 indicates not throttling.
*
* @param readThrottleBytesPerSecond
* @param writeThrottleBytesPerSecond
* @return
*/
HttpProxyServerBootstrap withThrottling(long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond);
/**
* All outgoing-communication of the proxy-instance is goin' to be routed via the given network-interface
*
* @param inetSocketAddress to be used for outgoing communication
*/
HttpProxyServerBootstrap withNetworkInterface(InetSocketAddress inetSocketAddress);
/**
* Sets the alias to use when adding Via headers to incoming and outgoing HTTP messages. The alias may be any
* pseudonym, or if not specified, defaults to the hostname of the local machine. See RFC 7230, section 5.7.1.
*
* @param alias the pseudonym to add to Via headers
*/
HttpProxyServerBootstrap withProxyAlias(String alias);
/**
*
* Build and starts the server.
*
*
* @return the newly built and started server
*/
HttpProxyServer start();
/**
* Set the configuration parameters for the proxy's thread pools.
*
* @param configuration thread pool configuration
* @return proxy server bootstrap for chaining
*/
HttpProxyServerBootstrap withThreadPoolConfiguration(ThreadPoolConfiguration configuration);
}