Add a Parent Proxy to a LittleProxy Listener
Bind a local LittleProxy listener with withAddress and supply its upstream parent through a ChainedProxyManager.
A local application can connect to LittleProxy while LittleProxy forwards its request through a corporate parent. Configure the listener and parent together:
ChainedProxy parent = new ChainedProxyAdapter() {
@Override
public InetSocketAddress getChainedProxyAddress() {
return new InetSocketAddress("proxy.office.example", 3128);
}
};
ChainedProxyManager manager = (request, candidates) ->
candidates.add(parent);
HttpProxyServer server = DefaultHttpProxyServer.bootstrap()
.withAddress(new InetSocketAddress("127.0.0.1", 8080))
.withChainProxyManager(manager)
.start();
This Java 8-or-later fragment uses LittleProxy's public chaining interfaces. The application using the proxy connects to 127.0.0.1:8080; the adapter returns the next proxy at proxy.office.example:3128.
The manager is consulted to supply upstream candidates for a request. This example adds the same parent each time. An application's routing rule can choose another candidate for a different destination. In an isolated public-site test permitted to use an unauthenticated public parent, the HTTP proxy list can supply that adapter’s address, with no parent-proxy credentials configured.
The chaining types are in org.littleshoot.proxy; DefaultHttpProxyServer is in its impl package.