Class DefaultHttpProxyServer
- All Implemented Interfaces:
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();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate final Collection<ActivityTracker>Track all ActivityTrackers for tracking proxying activity.private final ChannelGroupKeep track of all channels created by this proxy server for later shutdown when the proxy is stopped.private final booleanprivate final booleanprivate InetSocketAddressprivate final ChainedProxyManagerprivate intprivate static final StringThe 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 final HttpFiltersSourceprivate GlobalTrafficShapingHandlerprivate intprivate final ThreadJVM shutdown hook to shutdown this proxy server.private final InetSocketAddressprivate static final org.slf4j.Loggerprivate static final intprivate static final intprivate static final intprivate final intprivate final intprivate final intprivate final MitmManagerprivate final StringThe alias or pseudonym for this proxy, used when adding the Via header.private final ProxyAuthenticatorprivate final InetSocketAddressprivate final booleanprivate final ServerGroupOurServerGroup.private final HostResolverprivate final SslEngineSourceprivate final AtomicBooleanprivate static final longThe interval in ms at which the GlobalTrafficShapingHandler will run to compute and throttle the proxy-to-server bandwidth.private final booleanprivate final TransportProtocol -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDefaultHttpProxyServer(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. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Stops the server and all related clones immediately, without waiting for traffic to stop.static HttpProxyServerBootstrapBootstrap a newDefaultHttpProxyServerstarting from scratch.static HttpProxyServerBootstrapbootstrapFromFile(String path) Bootstrap a newDefaultHttpProxyServerusing defaults from the given file.clone()Clone the existing server, with a port 1 higher and everything else the same.protected voidcloseAllChannels(boolean graceful) Closes all channels opened by this proxy server.private GlobalTrafficShapingHandlercreateGlobalTrafficShapingHandler(TransportProtocol transportProtocol, long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) Creates a new GlobalTrafficShapingHandler for this HttpProxyServer, using this proxy's proxyToServerEventLoop.private voiddoStart()protected voiddoStop(boolean graceful) Performs cleanup necessary to stop the server.protected Collection<ActivityTracker>protected ChainedProxyManagerintReturns the maximum time to wait, in milliseconds, to connect to a server.intReturn the address on which this proxy is listening.intintintprotected MitmManagerprotected ProxyAuthenticatorprotected EventLoopGroupgetProxyToServerWorkerFor(TransportProtocol transportProtocol) longprotected SslEngineSourcelongbooleanbooleanboolean(package private) booleanprotected voidregisterChannel(Channel channel) Register a newChannelwith this server, for later closing.voidsetConnectTimeout(int connectTimeoutMs) Sets the maximum time to wait, in milliseconds, to connect to a server.voidsetIdleConnectionTimeout(int idleConnectionTimeout) voidsetThrottle(long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) Set the read/write throttle bandwidths (in bytes/second) for this proxy.private HttpProxyServerstart()voidstop()Stops the server and all related clones.protected voidunregisterChannel(Channel channel)
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
TRAFFIC_SHAPING_CHECK_INTERVAL_MS
private static final long TRAFFIC_SHAPING_CHECK_INTERVAL_MSThe interval in ms at which the GlobalTrafficShapingHandler will run to compute and throttle the proxy-to-server bandwidth.- See Also:
-
MAX_INITIAL_LINE_LENGTH_DEFAULT
private static final int MAX_INITIAL_LINE_LENGTH_DEFAULT- See Also:
-
MAX_HEADER_SIZE_DEFAULT
private static final int MAX_HEADER_SIZE_DEFAULT- See Also:
-
MAX_CHUNK_SIZE_DEFAULT
private static final int MAX_CHUNK_SIZE_DEFAULT- See Also:
-
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:
-
serverGroup
OurServerGroup. Multiple proxy servers can share the same ServerGroup in order to reuse threads and other such resources. -
transportProtocol
-
requestedAddress
-
localAddress
-
boundAddress
-
sslEngineSource
-
authenticateSslClients
private final boolean authenticateSslClients -
proxyAuthenticator
-
chainProxyManager
-
mitmManager
-
filtersSource
-
transparent
private final boolean transparent -
connectTimeout
private volatile int connectTimeout -
idleConnectionTimeout
private volatile int idleConnectionTimeout -
serverResolver
-
globalTrafficShapingHandler
-
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
The alias or pseudonym for this proxy, used when adding the Via header. -
stopped
-
activityTrackers
Track all ActivityTrackers for tracking proxying activity. -
allChannels
Keep track of all channels created by this proxy server for later shutdown when the proxy is stopped. -
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 Details
-
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 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 anSSLEngineobtained from thisSslEngineSource.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 providedProxyAuthenticatorchainProxyManager- The proxy to send requests to if chaining proxies. Typicallynull.mitmManager- TheMitmManagerto use for man in the middle'ing CONNECT requestsfiltersSource- Source forHttpFilterstransparent- 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- theHostResolverto 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.1acceptProxyProtocol- when true, the proxy will accept a proxy protocol header from clientsendProxyProtocol- when true, the proxy will send a proxy protocol header to the server
-
-
Method Details
-
bootstrap
Bootstrap a newDefaultHttpProxyServerstarting from scratch. -
bootstrapFromFile
Bootstrap a newDefaultHttpProxyServerusing defaults from the given file. -
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() -
getIdleConnectionTimeout
public int getIdleConnectionTimeout()- Specified by:
getIdleConnectionTimeoutin interfaceHttpProxyServer
-
setIdleConnectionTimeout
public void setIdleConnectionTimeout(int idleConnectionTimeout) - Specified by:
setIdleConnectionTimeoutin interfaceHttpProxyServer
-
getConnectTimeout
public int getConnectTimeout()Description copied from interface:HttpProxyServerReturns the maximum time to wait, in milliseconds, to connect to a server.- Specified by:
getConnectTimeoutin interfaceHttpProxyServer
-
setConnectTimeout
public void setConnectTimeout(int connectTimeoutMs) Description copied from interface:HttpProxyServerSets the maximum time to wait, in milliseconds, to connect to a server.- Specified by:
setConnectTimeoutin interfaceHttpProxyServer
-
getServerResolver
-
getLocalAddress
-
getListenAddress
Description copied from interface:HttpProxyServerReturn the address on which this proxy is listening.- Specified by:
getListenAddressin interfaceHttpProxyServer
-
setThrottle
public void setThrottle(long readThrottleBytesPerSecond, long writeThrottleBytesPerSecond) Description copied from interface:HttpProxyServerSet the read/write throttle bandwidths (in bytes/second) for this proxy.
- Specified by:
setThrottlein interfaceHttpProxyServer
-
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
Description copied from interface: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.
- Specified by:
clonein interfaceHttpProxyServer- Overrides:
clonein classObject- Returns:
- a bootstrap that allows customizing and starting the cloned server
-
stop
public void stop()Description copied from interface:HttpProxyServerStops the server and all related clones. Waits for traffic to stop before shutting down.- Specified by:
stopin interfaceHttpProxyServer
-
abort
public void abort()Description copied from interface:HttpProxyServerStops the server and all related clones immediately, without waiting for traffic to stop.- Specified by:
abortin interfaceHttpProxyServer
-
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
Register a newChannelwith this server, for later closing. -
unregisterChannel
-
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
-
start
-
doStart
private void doStart() -
getChainProxyManager
-
getMitmManager
-
getSslEngineSource
-
getProxyAuthenticator
-
getFiltersSource
-
getActivityTrackers
-
getProxyAlias
-
getProxyToServerWorkerFor
-