Package org.littleshoot.proxy
Class ChainedProxyAdapter
- java.lang.Object
-
- org.littleshoot.proxy.ChainedProxyAdapter
-
- All Implemented Interfaces:
ChainedProxy,SslEngineSource
public class ChainedProxyAdapter extends Object implements ChainedProxy
Convenience base class for implementations ofChainedProxy.
-
-
Field Summary
Fields Modifier and Type Field Description static ChainedProxyFALLBACK_TO_DIRECT_CONNECTIONChainedProxythat simply has the downstream proxy make a direct connection to the upstream server.
-
Constructor Summary
Constructors Constructor Description ChainedProxyAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconnectionFailed(Throwable cause)Called to let us know that connecting to this proxy failed.voidconnectionSucceeded()Called to let us know that connecting to this proxy succeeded.voiddisconnected()Called to let us know that we were disconnected.voidfilterRequest(HttpObject httpObject)Filters requests on their way to the chained proxy.InetSocketAddressgetChainedProxyAddress()Return theInetSocketAddressfor connecting to the chained proxy.ChainedProxyTypegetChainedProxyType()Tell LittleProxy the type of chained proxy that it will be connecting to.InetSocketAddressgetLocalAddress()(Optional) ensure that the connection is opened from a specific local address (useful when doing NAT traversal).StringgetPassword()(Optional) implement this method if the chained proxy requires a password.TransportProtocolgetTransportProtocol()Tell LittleProxy what kind of TransportProtocol to use to communicate with the chained proxy.StringgetUsername()(Optional) implement this method if the chained proxy requires a username.SSLEnginenewSslEngine()Returns anSSLEngineto use for a server connection from LittleProxy to the client.SSLEnginenewSslEngine(String peerHost, int peerPort)Returns anSSLEngineto use for a client connection from LittleProxy to the upstream server.booleanrequiresEncryption()Implement this method to tell LittleProxy whether to encrypt connections to the chained proxy for the given request.
-
-
-
Field Detail
-
FALLBACK_TO_DIRECT_CONNECTION
public static ChainedProxy FALLBACK_TO_DIRECT_CONNECTION
ChainedProxythat simply has the downstream proxy make a direct connection to the upstream server.
-
-
Method Detail
-
getChainedProxyAddress
public InetSocketAddress getChainedProxyAddress()
Description copied from interface:ChainedProxyReturn theInetSocketAddressfor connecting to the chained proxy. Returning null indicates that we won't chain.- Specified by:
getChainedProxyAddressin interfaceChainedProxy- Returns:
- The Chain Proxy with Host and Port.
-
getLocalAddress
public InetSocketAddress getLocalAddress()
Description copied from interface:ChainedProxy(Optional) ensure that the connection is opened from a specific local address (useful when doing NAT traversal).- Specified by:
getLocalAddressin interfaceChainedProxy
-
getTransportProtocol
public TransportProtocol getTransportProtocol()
Description copied from interface:ChainedProxyTell LittleProxy what kind of TransportProtocol to use to communicate with the chained proxy.- Specified by:
getTransportProtocolin interfaceChainedProxy
-
getChainedProxyType
public ChainedProxyType getChainedProxyType()
Description copied from interface:ChainedProxyTell LittleProxy the type of chained proxy that it will be connecting to. This setting determines what type of requests LittleProxy will use to communicate with the chained proxy.- Specified by:
getChainedProxyTypein interfaceChainedProxy- Returns:
- the chained proxy type.
-
getUsername
public String getUsername()
Description copied from interface:ChainedProxy(Optional) implement this method if the chained proxy requires a username.- Specified by:
getUsernamein interfaceChainedProxy- Returns:
- the username to send to the chained proxy.
-
getPassword
public String getPassword()
Description copied from interface:ChainedProxy(Optional) implement this method if the chained proxy requires a password.- Specified by:
getPasswordin interfaceChainedProxy- Returns:
- the password to send to the chained proxy.
-
requiresEncryption
public boolean requiresEncryption()
Description copied from interface:ChainedProxyImplement this method to tell LittleProxy whether to encrypt connections to the chained proxy for the given request. If true, LittleProxy will callSslEngineSource.newSslEngine()to obtain an SSLContext used by the downstream proxy.- Specified by:
requiresEncryptionin interfaceChainedProxy- Returns:
- true of the connection to the chained proxy should be encrypted
-
newSslEngine
public SSLEngine newSslEngine()
Description copied from interface:SslEngineSourceReturns anSSLEngineto use for a server connection from LittleProxy to the client.- Specified by:
newSslEnginein interfaceSslEngineSource
-
filterRequest
public void filterRequest(HttpObject httpObject)
Description copied from interface:ChainedProxyFilters requests on their way to the chained proxy.- Specified by:
filterRequestin interfaceChainedProxy
-
connectionSucceeded
public void connectionSucceeded()
Description copied from interface:ChainedProxyCalled to let us know that connecting to this proxy succeeded.- Specified by:
connectionSucceededin interfaceChainedProxy
-
connectionFailed
public void connectionFailed(Throwable cause)
Description copied from interface:ChainedProxyCalled to let us know that connecting to this proxy failed.- Specified by:
connectionFailedin interfaceChainedProxy- Parameters:
cause- exception that caused this failure (maybe null)
-
disconnected
public void disconnected()
Description copied from interface:ChainedProxyCalled to let us know that we were disconnected.- Specified by:
disconnectedin interfaceChainedProxy
-
newSslEngine
public SSLEngine newSslEngine(String peerHost, int peerPort)
Description copied from interface:SslEngineSourceReturns anSSLEngineto use for a client connection from LittleProxy to the upstream server. * Note: Peer information is needed to send the server_name extension in handshake with Server Name Indication (SNI).- Specified by:
newSslEnginein interfaceSslEngineSource- Parameters:
peerHost- to start a client connection to the server.peerPort- to start a client connection to the server.
-
-