Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 5bd2f52

Browse files
committed
direct resolution enabled through rest interface
1 parent 679d90d commit 5bd2f52

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

browsermob-core/src/main/java/net/lightbody/bmp/BrowserMobProxyServer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ public class BrowserMobProxyServer implements BrowserMobProxy {
229229
*/
230230
private volatile boolean useEcc = false;
231231

232+
private volatile boolean useDirect = false;
233+
232234
/**
233235
* Resolver to use when resolving hostnames to IP addresses. This is a bridge between {@link org.littleshoot.proxy.HostResolver} and
234236
* {@link net.lightbody.bmp.proxy.dns.AdvancedHostResolver}. It allows the resolvers to be changed on-the-fly without re-bootstrapping the
@@ -304,11 +306,15 @@ public int getMaximumResponseBufferSizeInBytes() {
304306
.withConnectTimeout(connectTimeoutMs)
305307
.withIdleConnectionTimeout(idleConnectionTimeoutSec)
306308
.withProxyAlias(VIA_HEADER_ALIAS);
309+
307310

308311
if (serverBindAddress != null) {
309312
bootstrap.withNetworkInterface(new InetSocketAddress(serverBindAddress, 0));
310313
}
311314

315+
if (useDirect) {
316+
bootstrap.withDirectResolutionEnabled(true);
317+
}
312318

313319
if (!mitmDisabled) {
314320
if (mitmManager == null) {
@@ -1030,6 +1036,10 @@ public void setUseEcc(boolean useEcc) {
10301036
this.useEcc = useEcc;
10311037
}
10321038

1039+
public void setUseDirect(boolean useDirect) {
1040+
this.useDirect = useDirect;
1041+
}
1042+
10331043
/**
10341044
* Adds the basic browsermob-proxy filters, except for the relatively-expensive HAR capture filter.
10351045
*/

browsermob-rest/src/main/java/net/lightbody/bmp/proxy/ProxyManager.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.lightbody.bmp.proxy;
1+
package net.lightbody.bmp.proxy;
22

33
import com.google.common.cache.Cache;
44
import com.google.common.cache.CacheBuilder;
@@ -131,7 +131,7 @@ public void onRemoval(RemovalNotification<Integer, LegacyProxyServer> removal) {
131131
}
132132
}
133133

134-
public LegacyProxyServer create(Map<String, String> options, Integer port, String bindAddr, String serverBindAddr, boolean useEcc, boolean trustAllServers) {
134+
public LegacyProxyServer create(Map<String, String> options, Integer port, String bindAddr, String serverBindAddr, boolean useEcc, boolean trustAllServers, boolean useDirect) {
135135
LOG.debug("Instantiate ProxyServer...");
136136
LegacyProxyServer proxy = proxyServerProvider.get();
137137

@@ -151,6 +151,12 @@ public LegacyProxyServer create(Map<String, String> options, Integer port, Strin
151151
}
152152
}
153153

154+
if (useDirect) {
155+
if (proxy instanceof BrowserMobProxyServer) {
156+
((BrowserMobProxyServer) proxy).setUseDirect(true);
157+
}
158+
}
159+
154160
if (options != null) {
155161
// this is a short-term work-around for Proxy Auth in the REST API until the upcoming REST API refactor
156162
String proxyUsername = options.remove("proxyUsername");
@@ -205,24 +211,28 @@ public LegacyProxyServer create(Map<String, String> options, Integer port, Strin
205211
throw new ProxyPortsExhaustedException();
206212
}
207213

214+
public LegacyProxyServer create(Map<String, String> options, Integer port, String bindAddr, boolean useEcc, boolean trustAllServers, boolean useDirect) {
215+
return create(options, port, null, null, false, false, useDirect);
216+
}
217+
208218
public LegacyProxyServer create(Map<String, String> options, Integer port, String bindAddr, boolean useEcc, boolean trustAllServers) {
209-
return create(options, port, null, null, false, false);
219+
return create(options, port, null, null, false, false, false);
210220
}
211221

212222
public LegacyProxyServer create(Map<String, String> options, Integer port) {
213-
return create(options, port, null, null, false, false);
223+
return create(options, port, null, null, false, false, false);
214224
}
215225

216226
public LegacyProxyServer create(Map<String, String> options) {
217-
return create(options, null, null, null, false, false);
227+
return create(options, null, null, null, false, false, false);
218228
}
219229

220230
public LegacyProxyServer create() {
221-
return create(null, null, null, null, false, false);
231+
return create(null, null, null, null, false, false, false);
222232
}
223233

224234
public LegacyProxyServer create(int port) {
225-
return create(null, port, null, null, false, false);
235+
return create(null, port, null, null, false, false, false);
226236
}
227237

228238
public LegacyProxyServer get(int port) {

browsermob-rest/src/main/java/net/lightbody/bmp/proxy/bricks/ProxyResource.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,19 @@ public Reply<?> newProxy(Request<String> request) {
103103
String trustAllServersString = request.param("trustAllServers");
104104
boolean trustAllServers = Boolean.parseBoolean(trustAllServersString);
105105

106+
String useDirectString = request.param("direct");
107+
boolean useDirect = false;
108+
if (httpProxy != null && useDirectString != null) {
109+
useDirect = Boolean.parseBoolean(useDirectString);
110+
}
111+
112+
System.out.println("Chase -> useDirect is " + useDirect);
113+
106114
LOG.debug("POST proxy instance on bindAddress `{}` & port `{}` & serverBindAddress `{}`",
107115
paramBindAddr, paramPort, paramServerBindAddr);
108116
LegacyProxyServer proxy;
109117
try {
110-
proxy = proxyManager.create(options, paramPort, paramBindAddr, paramServerBindAddr, useEcc, trustAllServers);
118+
proxy = proxyManager.create(options, paramPort, paramBindAddr, paramServerBindAddr, useEcc, trustAllServers, useDirect);
111119
} catch (ProxyExistsException ex) {
112120
return Reply.with(new ProxyDescriptor(ex.getPort())).status(455).as(Json.class);
113121
} catch (ProxyPortsExhaustedException ex) {

install_lp.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cd /Users/chasecook/Documents/work_stuff/browsermob-proxy
2+
mvn install:install-file -Dfile=/Users/chasecook/Desktop/littleproxy-1.1.0-beta-bmp-17-sources/target/littleproxy-1.1.0-beta-bmp-17.jar -DgroupId=net.lightbody.bmp -DartifactId=littleproxy -Dversion=1.1.0-beta-bmp-17 -Dpackaging=jar
3+
4+
5+
cd browsermob-core
6+
mvn install:install-file -Dfile=/Users/chasecook/Desktop/littleproxy-1.1.0-beta-bmp-17-sources/target/littleproxy-1.1.0-beta-bmp-17.jar -DgroupId=net.lightbody.bmp -DartifactId=littleproxy -Dversion=1.1.0-beta-bmp-17 -Dpackaging=jar
7+
8+
cd ../mitm
9+
mvn install:install-file -Dfile=/Users/chasecook/Desktop/littleproxy-1.1.0-beta-bmp-17-sources/target/littleproxy-1.1.0-beta-bmp-17.jar -DgroupId=net.lightbody.bmp -DartifactId=littleproxy -Dversion=1.1.0-beta-bmp-17 -Dpackaging=jar
10+
11+
cd /Users/chasecook/Documents/work_stuff/browsermob-proxy
12+
13+
# rebuild bmp
14+
mvn -DskipTests
15+
16+
# start bmp
17+
java -jar browsermob-dist/target/browsermob-dist-2.1.6-SNAPSHOT.jar

0 commit comments

Comments
 (0)