@@ -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 , boolean useEcc , boolean trustAllServers ) {
134+ public LegacyProxyServer create (Map <String , String > options , Integer port , String bindAddr , String serverBindAddr , boolean useEcc , boolean trustAllServers ) {
135135 LOG .debug ("Instantiate ProxyServer..." );
136136 LegacyProxyServer proxy = proxyServerProvider .get ();
137137
@@ -177,43 +177,59 @@ public LegacyProxyServer create(Map<String, String> options, Integer port, Strin
177177 proxy .setLocalHost (inetAddress );
178178 }
179179
180+ InetAddress serverInetAddress = null ;
181+ if (serverBindAddr != null ) {
182+ LOG .debug ("Bind ProxyServer serverAddress to `{}`..." , serverBindAddr );
183+ try {
184+ serverInetAddress = InetAddress .getByName (serverBindAddr );
185+ } catch (UnknownHostException e ) {
186+ LOG .error ("Unable to bind proxy to server address: " + serverBindAddr + "; proxy will not be created." , e );
187+
188+ throw new RuntimeException ("Unable to bind proxy to server address: " , e );
189+ }
190+ }
191+
180192 if (port != null ) {
181- return startProxy (proxy , port );
193+ return startProxy (proxy , port , serverInetAddress );
182194 }
183195
184196 while (proxies .size () <= maxPort - minPort ) {
185197 LOG .debug ("Use next available port for new ProxyServer..." );
186198 port = nextPort ();
187199 try {
188- return startProxy (proxy , port );
200+ return startProxy (proxy , port , serverInetAddress );
189201 } catch (ProxyExistsException ex ) {
190202 LOG .debug ("Proxy already exists at port {}" , port );
191203 }
192204 }
193205 throw new ProxyPortsExhaustedException ();
194206 }
195207
208+ public LegacyProxyServer create (Map <String , String > options , Integer port , String bindAddr , boolean useEcc , boolean trustAllServers ) {
209+ return create (options , port , null , null , false , false );
210+ }
211+
196212 public LegacyProxyServer create (Map <String , String > options , Integer port ) {
197- return create (options , port , null , false , false );
213+ return create (options , port , null , null , false , false );
198214 }
199215
200216 public LegacyProxyServer create (Map <String , String > options ) {
201- return create (options , null , null , false , false );
217+ return create (options , null , null , null , false , false );
202218 }
203219
204220 public LegacyProxyServer create () {
205- return create (null , null , null , false , false );
221+ return create (null , null , null , null , false , false );
206222 }
207223
208224 public LegacyProxyServer create (int port ) {
209- return create (null , port , null , false , false );
225+ return create (null , port , null , null , false , false );
210226 }
211227
212228 public LegacyProxyServer get (int port ) {
213229 return proxies .get (port );
214230 }
215231
216- private LegacyProxyServer startProxy (LegacyProxyServer proxy , int port ) {
232+ private LegacyProxyServer startProxy (LegacyProxyServer proxy , int port , InetAddress serverBindAddr ) {
217233 if (port != 0 ) {
218234 proxy .setPort (port );
219235 LegacyProxyServer old = proxies .putIfAbsent (port , proxy );
@@ -224,7 +240,13 @@ private LegacyProxyServer startProxy(LegacyProxyServer proxy, int port) {
224240 }
225241
226242 try {
227- proxy .start ();
243+ if (serverBindAddr != null && proxy instanceof BrowserMobProxyServer ) {
244+ BrowserMobProxyServer bProxy = (BrowserMobProxyServer ) proxy ;
245+ bProxy .start (port , null , serverBindAddr );
246+ } else {
247+ proxy .start ();
248+ }
249+
228250 if (port == 0 ) {
229251 int realPort = proxy .getPort ();
230252 proxies .put (realPort , proxy );
0 commit comments