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 io.netty.channel.group.ChannelGroup |
allChannels
Keep track of all channels created by this proxy server for later shutdown when the proxy is stopped.
|
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 io.netty.handler.traffic.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 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)
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 io.netty.handler.traffic.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() |
protected MitmManager |
getMitmManager() |
String |
getProxyAlias() |
protected ProxyAuthenticator |
getProxyAuthenticator() |
protected io.netty.channel.EventLoopGroup |
getProxyToServerWorkerFor(TransportProtocol transportProtocol) |
long |
getReadThrottle() |
HostResolver |
getServerResolver() |
protected SslEngineSource |
getSslEngineSource() |
long |
getWriteThrottle() |
(package private) boolean |
isTransparent() |
protected void |
registerChannel(io.netty.channel.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 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 io.netty.handler.traffic.GlobalTrafficShapingHandler globalTrafficShapingHandler
private final String proxyAlias
private final AtomicBoolean stopped
private final Collection<ActivityTracker> activityTrackers
private final io.netty.channel.group.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)
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
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 requestsfiltersSource
- 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 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 bandwidthpublic static HttpProxyServerBootstrap bootstrap()
DefaultHttpProxyServer
starting from scratch.public static HttpProxyServerBootstrap bootstrapFromFile(String path)
DefaultHttpProxyServer
using defaults from the
given file.path
- private io.netty.handler.traffic.GlobalTrafficShapingHandler createGlobalTrafficShapingHandler(TransportProtocol transportProtocol, long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond)
transportProtocol
- readThrottleBytesPerSecond
- writeThrottleBytesPerSecond
- boolean isTransparent()
public int getIdleConnectionTimeout()
getIdleConnectionTimeout
in interface HttpProxyServer
public void setIdleConnectionTimeout(int idleConnectionTimeout)
setIdleConnectionTimeout
in interface HttpProxyServer
public int getConnectTimeout()
HttpProxyServer
getConnectTimeout
in interface HttpProxyServer
public void setConnectTimeout(int connectTimeoutMs)
HttpProxyServer
setConnectTimeout
in interface HttpProxyServer
public HostResolver getServerResolver()
public InetSocketAddress getLocalAddress()
public InetSocketAddress getListenAddress()
HttpProxyServer
getListenAddress
in interface HttpProxyServer
public void setThrottle(long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond)
HttpProxyServer
Set the read/write throttle bandwidths (in bytes/second) for this proxy.
setThrottle
in interface HttpProxyServer
public long getReadThrottle()
public long getWriteThrottle()
public HttpProxyServerBootstrap clone()
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.
clone
in interface HttpProxyServer
clone
in class Object
public void stop()
HttpProxyServer
stop
in interface HttpProxyServer
public void abort()
HttpProxyServer
abort
in interface HttpProxyServer
protected void doStop(boolean graceful)
graceful
- when true, waits for requests to terminate before stopping the serverprotected void registerChannel(io.netty.channel.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()
public String getProxyAlias()
protected io.netty.channel.EventLoopGroup getProxyToServerWorkerFor(TransportProtocol transportProtocol)
Copyright © 2009–2018 LittleShoot. All rights reserved.