public class DefaultHttpProxyServer extends Object implements HttpProxyServer
Primary implementation of an HttpProxyServer.
DefaultHttpProxyServer is bootstrapped by calling
bootstrap() or bootstrapFromFile(String), and then calling
DefaultHttpProxyServer.DefaultHttpProxyServerBootstrap.start(). For example:
DefaultHttpProxyServer server =
DefaultHttpProxyServer
.bootstrap()
.withPort(8090)
.start();
| Modifier and Type | Class and Description |
|---|---|
private static class |
DefaultHttpProxyServer.DefaultHttpProxyServerBootstrap |
| Modifier and Type | Field and Description |
|---|---|
private Collection<ActivityTracker> |
activityTrackers
Track all ActivityTrackers for tracking proxying activity.
|
private ChannelGroup |
allChannels
Keep track of all channels created by this proxy server for later shutdown when the proxy is stopped.
|
private boolean |
allowRequestsToOriginServer |
private boolean |
authenticateSslClients |
private InetSocketAddress |
boundAddress |
private ChainedProxyManager |
chainProxyManager |
private int |
connectTimeout |
private static 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.
|
private HttpFiltersSource |
filtersSource |
private GlobalTrafficShapingHandler |
globalTrafficShapingHandler |
private int |
idleConnectionTimeout |
private Thread |
jvmShutdownHook
JVM shutdown hook to shutdown this proxy server.
|
private InetSocketAddress |
localAddress |
private static org.slf4j.Logger |
LOG |
private static int |
MAX_CHUNK_SIZE_DEFAULT |
private static int |
MAX_HEADER_SIZE_DEFAULT |
private static int |
MAX_INITIAL_LINE_LENGTH_DEFAULT |
private int |
maxChunkSize |
private int |
maxHeaderSize |
private int |
maxInitialLineLength |
private MitmManager |
mitmManager |
private String |
proxyAlias
The alias or pseudonym for this proxy, used when adding the Via header.
|
private ProxyAuthenticator |
proxyAuthenticator |
private InetSocketAddress |
requestedAddress |
private ServerGroup |
serverGroup
Our
ServerGroup. |
private HostResolver |
serverResolver |
private SslEngineSource |
sslEngineSource |
private AtomicBoolean |
stopped
|
private static 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.
|
private boolean |
transparent |
private TransportProtocol |
transportProtocol |
| Modifier | Constructor and Description |
|---|---|
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)
Creates a new proxy server.
|
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Stops the server and all related clones immediately, without waiting for traffic to stop.
|
static HttpProxyServerBootstrap |
bootstrap()
Bootstrap a new
DefaultHttpProxyServer starting from scratch. |
static HttpProxyServerBootstrap |
bootstrapFromFile(String path)
Bootstrap a new
DefaultHttpProxyServer using defaults from the
given file. |
HttpProxyServerBootstrap |
clone()
Clone the existing server, with a port 1 higher and everything else the
same.
|
protected void |
closeAllChannels(boolean graceful)
Closes all channels opened by this proxy server.
|
private GlobalTrafficShapingHandler |
createGlobalTrafficShapingHandler(TransportProtocol transportProtocol,
long readThrottleBytesPerSecond,
long writeThrottleBytesPerSecond)
Creates a new GlobalTrafficShapingHandler for this HttpProxyServer, using this proxy's proxyToServerEventLoop.
|
private void |
doStart() |
protected void |
doStop(boolean graceful)
Performs cleanup necessary to stop the server.
|
protected Collection<ActivityTracker> |
getActivityTrackers() |
protected ChainedProxyManager |
getChainProxyManager() |
int |
getConnectTimeout()
Returns the maximum time to wait, in milliseconds, to connect to a server.
|
HttpFiltersSource |
getFiltersSource() |
int |
getIdleConnectionTimeout() |
InetSocketAddress |
getListenAddress()
Return the address on which this proxy is listening.
|
InetSocketAddress |
getLocalAddress() |
int |
getMaxChunkSize() |
int |
getMaxHeaderSize() |
int |
getMaxInitialLineLength() |
protected MitmManager |
getMitmManager() |
String |
getProxyAlias() |
protected ProxyAuthenticator |
getProxyAuthenticator() |
protected EventLoopGroup |
getProxyToServerWorkerFor(TransportProtocol transportProtocol) |
long |
getReadThrottle() |
HostResolver |
getServerResolver() |
protected SslEngineSource |
getSslEngineSource() |
long |
getWriteThrottle() |
boolean |
isAllowRequestsToOriginServer() |
(package private) boolean |
isTransparent() |
protected void |
registerChannel(Channel channel)
Register a new
Channel with this server, for later closing. |
void |
setConnectTimeout(int connectTimeoutMs)
Sets the maximum time to wait, in milliseconds, to connect to a server.
|
void |
setIdleConnectionTimeout(int idleConnectionTimeout) |
void |
setThrottle(long readThrottleBytesPerSecond,
long writeThrottleBytesPerSecond)
Set the read/write throttle bandwidths (in bytes/second) for this proxy.
|
private HttpProxyServer |
start() |
void |
stop()
Stops the server and all related clones.
|
private static final org.slf4j.Logger LOG
private static final long TRAFFIC_SHAPING_CHECK_INTERVAL_MS
private static final int MAX_INITIAL_LINE_LENGTH_DEFAULT
private static final int MAX_HEADER_SIZE_DEFAULT
private static final int MAX_CHUNK_SIZE_DEFAULT
private static final String FALLBACK_PROXY_ALIAS
private final ServerGroup serverGroup
ServerGroup. Multiple proxy servers can share the same
ServerGroup in order to reuse threads and other such resources.private final TransportProtocol transportProtocol
private final InetSocketAddress requestedAddress
private volatile InetSocketAddress localAddress
private volatile InetSocketAddress boundAddress
private final SslEngineSource sslEngineSource
private final boolean authenticateSslClients
private final ProxyAuthenticator proxyAuthenticator
private final ChainedProxyManager chainProxyManager
private final MitmManager mitmManager
private final HttpFiltersSource filtersSource
private final boolean transparent
private volatile int connectTimeout
private volatile int idleConnectionTimeout
private final HostResolver serverResolver
private volatile GlobalTrafficShapingHandler globalTrafficShapingHandler
private final int maxInitialLineLength
private final int maxHeaderSize
private final int maxChunkSize
private final boolean allowRequestsToOriginServer
private final AtomicBoolean stopped
private final String proxyAlias
private final Collection<ActivityTracker> activityTrackers
private final ChannelGroup allChannels
private final Thread jvmShutdownHook
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)
serverGroup - our ServerGroup for shared thread pools and suchtransportProtocol - The protocol to use for data transportrequestedAddress - The address on which this server will listensslEngineSource - (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 SSLproxyAuthenticator - (optional) If specified, requests to the proxy will be
authenticated using HTTP BASIC authentication per the provided
ProxyAuthenticatorchainProxyManager - The proxy to send requests to if chaining proxies. Typically
null.mitmManager - The MitmManager to use for man in the middle'ing
CONNECT requestsfiltersSource - Source for HttpFilterstransparent - 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 proxyconnectTimeout - number of milliseconds to wait to connect to the upstream
serverserverResolver - the HostResolver to use for resolving server addressesreadThrottleBytesPerSecond - read throttle bandwidthwriteThrottleBytesPerSecond - write throttle bandwidthmaxInitialLineLength - maxHeaderSize - maxChunkSize - allowRequestsToOriginServer - when true, allow the proxy to handle requests that contain an origin-form URI, as defined in RFC 7230 5.3.1public static HttpProxyServerBootstrap bootstrap()
DefaultHttpProxyServer starting from scratch.public static HttpProxyServerBootstrap bootstrapFromFile(String path)
DefaultHttpProxyServer using defaults from the
given file.path - private GlobalTrafficShapingHandler createGlobalTrafficShapingHandler(TransportProtocol transportProtocol, long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond)
transportProtocol - readThrottleBytesPerSecond - writeThrottleBytesPerSecond - boolean isTransparent()
public int getIdleConnectionTimeout()
getIdleConnectionTimeout in interface HttpProxyServerpublic void setIdleConnectionTimeout(int idleConnectionTimeout)
setIdleConnectionTimeout in interface HttpProxyServerpublic int getConnectTimeout()
HttpProxyServergetConnectTimeout in interface HttpProxyServerpublic void setConnectTimeout(int connectTimeoutMs)
HttpProxyServersetConnectTimeout in interface HttpProxyServerpublic HostResolver getServerResolver()
public InetSocketAddress getLocalAddress()
public InetSocketAddress getListenAddress()
HttpProxyServergetListenAddress in interface HttpProxyServerpublic void setThrottle(long readThrottleBytesPerSecond,
long writeThrottleBytesPerSecond)
HttpProxyServerSet the read/write throttle bandwidths (in bytes/second) for this proxy.
setThrottle in interface HttpProxyServerpublic long getReadThrottle()
public long getWriteThrottle()
public int getMaxInitialLineLength()
public int getMaxHeaderSize()
public int getMaxChunkSize()
public boolean isAllowRequestsToOriginServer()
public HttpProxyServerBootstrap clone()
HttpProxyServerClone 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.
clone in interface HttpProxyServerclone in class Objectpublic void stop()
HttpProxyServerstop in interface HttpProxyServerpublic void abort()
HttpProxyServerabort in interface HttpProxyServerprotected void doStop(boolean graceful)
graceful - when true, waits for requests to terminate before stopping the serverprotected void registerChannel(Channel channel)
Channel with this server, for later closing.channel - protected void closeAllChannels(boolean graceful)
graceful - when false, attempts to shutdown all channels immediately and ignores any channel-closing exceptionsprivate HttpProxyServer start()
private void doStart()
protected ChainedProxyManager getChainProxyManager()
protected MitmManager getMitmManager()
protected SslEngineSource getSslEngineSource()
protected ProxyAuthenticator getProxyAuthenticator()
public HttpFiltersSource getFiltersSource()
protected Collection<ActivityTracker> getActivityTrackers()
protected EventLoopGroup getProxyToServerWorkerFor(TransportProtocol transportProtocol)
public String getProxyAlias()
Copyright © 2009–2017 LittleShoot. All rights reserved.