Skip to content

Commit 415f502

Browse files
committed
Extend HTTP API with custom proxy ports
Optionally specify the port you want to run on when creating a proxy
1 parent 87c5851 commit 415f502

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/java/org/browsermob/proxy/bricks/ProxyResource.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ public Reply<ProxyDescriptor> newProxy(Request request) throws Exception {
4343
options.put("httpProxy", httpProxy);
4444
}
4545

46-
ProxyServer proxy = proxyManager.create(options);
47-
int port = proxy.getPort();
48-
46+
String paramPort = request.param("port");
47+
int port = 0;
48+
if (paramPort != null) {
49+
port = Integer.parseInt(paramPort);
50+
ProxyServer proxy = proxyManager.create(options, port);
51+
} else {
52+
ProxyServer proxy = proxyManager.create(options);
53+
port = proxy.getPort();
54+
}
4955
return Reply.with(new ProxyDescriptor(port)).as(Json.class);
5056
}
5157

0 commit comments

Comments
 (0)