Skip to content

Commit 8e3bc74

Browse files
authored
Proxy Settings added to OWASP Benchmark Crawler to enable different hosts (#1) (#12)
1 parent 1461b89 commit 8e3bc74

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

plugin/src/main/java/org/owasp/benchmarkutils/tools/BenchmarkCrawler.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.commons.cli.ParseException;
3939
import org.apache.commons.lang.time.StopWatch;
4040
import org.apache.http.HttpEntity;
41+
import org.apache.http.HttpHost;
4142
import org.apache.http.client.methods.CloseableHttpResponse;
4243
import org.apache.http.client.methods.HttpPost;
4344
import org.apache.http.client.methods.HttpUriRequest;
@@ -62,6 +63,8 @@
6263
@Mojo(name = "run-crawler", requiresProject = false, defaultPhase = LifecyclePhase.COMPILE)
6364
public class BenchmarkCrawler extends AbstractMojo {
6465

66+
public static String proxyHost, proxyPort;
67+
6568
@Parameter(property = "crawlerFile")
6669
String pluginFilenameParam;
6770

@@ -191,9 +194,22 @@ static CloseableHttpClient createAcceptSelfSignedCertificateClient()
191194
SSLConnectionSocketFactory connectionFactory =
192195
new SSLConnectionSocketFactory(sslContext, allowAllHosts);
193196

194-
// finally create the HttpClient using HttpClient factory methods and assign the SSL Socket
195-
// Factory
196-
return HttpClients.custom().setSSLSocketFactory(connectionFactory).build();
197+
// Set Proxy settings
198+
HttpHost httpHost = null;
199+
if ((proxyHost = System.getProperty("proxyHost")) != null
200+
&& (proxyPort = System.getProperty("proxyPort")) != null) {
201+
httpHost = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
202+
// finally create the HttpClient using HttpClient factory methods and assign the SSL
203+
// Socket Factory and assign the setProxy
204+
return HttpClients.custom()
205+
.setSSLSocketFactory(connectionFactory)
206+
.setProxy(httpHost)
207+
.build();
208+
} else {
209+
// finally create the HttpClient using HttpClient factory methods and assign the SSL
210+
// Socket Factory
211+
return HttpClients.custom().setSSLSocketFactory(connectionFactory).build();
212+
}
197213
}
198214

199215
/**

0 commit comments

Comments
 (0)