55
55
import org .littleshoot .proxy .HttpProxyServerBootstrap ;
56
56
import org .littleshoot .proxy .impl .DefaultHttpProxyServer ;
57
57
import org .littleshoot .proxy .impl .ProxyUtils ;
58
+ import org .littleshoot .proxy .impl .ThreadPoolConfiguration ;
58
59
import org .openqa .selenium .Proxy ;
59
60
import org .slf4j .Logger ;
60
61
import org .slf4j .LoggerFactory ;
@@ -198,6 +199,11 @@ public class BrowserMobProxyServer implements BrowserMobProxy, LegacyProxyServer
198
199
*/
199
200
private volatile InetSocketAddress upstreamProxyAddress ;
200
201
202
+ /**
203
+ * The chained proxy manager that manages upstream proxies.
204
+ */
205
+ private volatile ChainedProxyManager chainedProxyManager ;
206
+
201
207
/**
202
208
* The address and socket on which the proxy will listen for client requests.
203
209
*/
@@ -232,6 +238,11 @@ public class BrowserMobProxyServer implements BrowserMobProxy, LegacyProxyServer
232
238
233
239
private final ActivityMonitor activityMonitor = new ActivityMonitor ();
234
240
241
+ /**
242
+ * The acceptor and worker thread configuration for the Netty thread pools.
243
+ */
244
+ private volatile ThreadPoolConfiguration threadPoolConfiguration ;
245
+
235
246
/**
236
247
* Adapter to enable clients to switch to a LittleProxy implementation of BrowserMobProxy but maintain compatibility with
237
248
* the 2.0.0 interface.
@@ -341,20 +352,29 @@ public int getMaximumResponseBufferSizeInBytes() {
341
352
bootstrap .withThrottling (readBandwidthLimitBps , writeBandwidthLimitBps );
342
353
}
343
354
344
- if (upstreamProxyAddress != null ) {
355
+ if (chainedProxyManager != null ) {
356
+ bootstrap .withChainProxyManager (chainedProxyManager );
357
+ } else if (upstreamProxyAddress != null ) {
345
358
bootstrap .withChainProxyManager (new ChainedProxyManager () {
346
359
@ Override
347
360
public void lookupChainedProxies (HttpRequest httpRequest , Queue <ChainedProxy > chainedProxies ) {
348
- chainedProxies .add (new ChainedProxyAdapter () {
349
- @ Override
350
- public InetSocketAddress getChainedProxyAddress () {
351
- return upstreamProxyAddress ;
352
- }
353
- });
361
+ final InetSocketAddress upstreamProxy = upstreamProxyAddress ;
362
+ if (upstreamProxy != null ) {
363
+ chainedProxies .add (new ChainedProxyAdapter () {
364
+ @ Override
365
+ public InetSocketAddress getChainedProxyAddress () {
366
+ return upstreamProxy ;
367
+ }
368
+ });
369
+ }
354
370
}
355
371
});
356
372
}
357
373
374
+ if (threadPoolConfiguration != null ) {
375
+ bootstrap .withThreadPoolConfiguration (threadPoolConfiguration );
376
+ }
377
+
358
378
proxyServer = bootstrap .start ();
359
379
}
360
380
@@ -1128,6 +1148,8 @@ public boolean waitForQuiescence(long quietPeriod, long timeout, TimeUnit timeUn
1128
1148
/**
1129
1149
* Instructs this proxy to route traffic through an upstream proxy. Proxy chaining is not compatible with man-in-the-middle
1130
1150
* SSL, so HAR capture will be disabled for HTTPS traffic when using an upstream proxy.
1151
+ * <p/>
1152
+ * <b>Note:</b> Using {@link #setChainedProxyManager(ChainedProxyManager)} will supersede any value set by this method.
1131
1153
*
1132
1154
* @param chainedProxyAddress address of the upstream proxy
1133
1155
*/
@@ -1141,6 +1163,34 @@ public InetSocketAddress getChainedProxy() {
1141
1163
return upstreamProxyAddress ;
1142
1164
}
1143
1165
1166
+ /**
1167
+ * Allows access to the LittleProxy {@link ChainedProxyManager} for fine-grained control of the chained proxies. To enable a single
1168
+ * chained proxy, {@link BrowserMobProxy#setChainedProxy(InetSocketAddress)} is generally more convenient.
1169
+ *
1170
+ * @param chainedProxyManager chained proxy manager to enable
1171
+ */
1172
+ public void setChainedProxyManager (ChainedProxyManager chainedProxyManager ) {
1173
+ if (isStarted ()) {
1174
+ throw new IllegalStateException ("Cannot configure chained proxy manager after proxy has started." );
1175
+ }
1176
+
1177
+ this .chainedProxyManager = chainedProxyManager ;
1178
+ }
1179
+
1180
+ /**
1181
+ * Configures the Netty thread pool used by the LittleProxy back-end. See {@link ThreadPoolConfiguration} for details.
1182
+ *
1183
+ * @param threadPoolConfiguration thread pool configuration to use
1184
+ *
1185
+ */
1186
+ public void setThreadPoolConfiguration (ThreadPoolConfiguration threadPoolConfiguration ) {
1187
+ if (isStarted ()) {
1188
+ throw new IllegalStateException ("Cannot configure thread pool after proxy has started." );
1189
+ }
1190
+
1191
+ this .threadPoolConfiguration = threadPoolConfiguration ;
1192
+ }
1193
+
1144
1194
@ Override
1145
1195
public void addFirstHttpFilterFactory (HttpFiltersSource filterFactory ) {
1146
1196
filterFactories .add (0 , filterFactory );
0 commit comments