@@ -198,6 +198,12 @@ public class BrowserMobProxyServer implements BrowserMobProxy {
198198 */
199199 private final AtomicBoolean harCaptureFilterEnabled = new AtomicBoolean (false );
200200
201+ /**
202+ * Set to true when LittleProxy has been bootstrapped with the default chained proxy. This allows modifying the chained proxy
203+ * after the proxy has been started.
204+ */
205+ private final AtomicBoolean bootstrappedWithDefaultChainedProxy = new AtomicBoolean (false );
206+
201207 /**
202208 * The address of an upstream chained proxy to route traffic through.
203209 */
@@ -327,6 +333,10 @@ public int getMaximumResponseBufferSizeInBytes() {
327333 if (chainedProxyManager != null ) {
328334 bootstrap .withChainProxyManager (chainedProxyManager );
329335 } else if (upstreamProxyAddress != null ) {
336+ // indicate that the proxy was bootstrapped with the default chained proxy manager, which allows changing the
337+ // chained proxy after the proxy is started.
338+ bootstrappedWithDefaultChainedProxy .set (true );
339+
330340 bootstrap .withChainProxyManager (new ChainedProxyManager () {
331341 @ Override
332342 public void lookupChainedProxies (HttpRequest httpRequest , Queue <ChainedProxy > chainedProxies ) {
@@ -860,15 +870,19 @@ public boolean waitForQuiescence(long quietPeriod, long timeout, TimeUnit timeUn
860870 }
861871
862872 /**
863- * Instructs this proxy to route traffic through an upstream proxy. Proxy chaining is not compatible with man-in-the-middle
864- * SSL, so HAR capture will be disabled for HTTPS traffic when using an upstream proxy.
865- * <p>
866- * <b>Note:</b> Using {@link #setChainedProxyManager(ChainedProxyManager)} will supersede any value set by this method .
873+ * Instructs this proxy to route traffic through an upstream proxy.
874+ *
875+ * <b>Note:</b> Using {@link #setChainedProxyManager(ChainedProxyManager)} will supersede any value set by this method. A chained
876+ * proxy must be set before the proxy is started, though it can be changed after the proxy is started .
867877 *
868878 * @param chainedProxyAddress address of the upstream proxy
869879 */
870880 @ Override
871881 public void setChainedProxy (InetSocketAddress chainedProxyAddress ) {
882+ if (isStarted () && !bootstrappedWithDefaultChainedProxy .get ()) {
883+ throw new IllegalStateException ("Cannot set a chained proxy after the proxy is started if the proxy was started without a chained proxy." );
884+ }
885+
872886 upstreamProxyAddress = chainedProxyAddress ;
873887 }
874888
@@ -881,6 +895,8 @@ public InetSocketAddress getChainedProxy() {
881895 * Allows access to the LittleProxy {@link ChainedProxyManager} for fine-grained control of the chained proxies. To enable a single
882896 * chained proxy, {@link BrowserMobProxy#setChainedProxy(InetSocketAddress)} is generally more convenient.
883897 *
898+ * <b>Note:</b> The chained proxy manager must be enabled before calling {@link #start()}.
899+ *
884900 * @param chainedProxyManager chained proxy manager to enable
885901 */
886902 public void setChainedProxyManager (ChainedProxyManager chainedProxyManager ) {
0 commit comments