import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
import org.hedgecode.chess.scanner.Scanner;
import org.hedgecode.chess.scanner.ScannerException;
+import org.hedgecode.chess.scanner.proxy.Proxy;
import org.hedgecode.chess.scanner.regex.RegexMatcher;
import org.hedgecode.chess.scanner.regex.RegexResult;
import org.hedgecode.chess.scanner.regex.RegexType;
}
protected String request(String url, boolean withCrlf) throws ScannerException {
- HttpGet request = new HttpGet(url);
- CloseableHttpResponse response = null;
StringBuilder sb = new StringBuilder();
- try {
- response = getClient().execute(request);
+ try (CloseableHttpResponse response = getClient().execute(
+ new HttpGet(url), getContext()
+ )) {
try (BufferedReader br = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(), CHARSET
throw new ScannerException(
String.format("Error occurred for requesting URL: %s", url), cause
);
- } finally {
- if (response != null) {
- try {
- response.close();
- } catch (IOException ignored) {}
- }
}
return sb.toString();
}
protected RegexResult matchRequest(String url, RegexMatcher matcher, boolean isFirst)
throws ScannerException
{
- HttpGet request = new HttpGet(url);
- CloseableHttpResponse response = null;
- try {
- response = getClient().execute(request);
+ try (CloseableHttpResponse response = getClient().execute(
+ new HttpGet(url), getContext()
+ )) {
try (BufferedReader br = new BufferedReader(
new InputStreamReader(
response.getEntity().getContent(),
throw new ScannerException(
String.format("Error occurred for requesting URL: %s", url), cause
);
- } finally {
- if (response != null) {
- try {
- response.close();
- } catch (IOException ignored) {}
- }
}
return matcher.result();
}
private CloseableHttpClient getClient() {
- return HttpClients.createMinimal();
+ return Proxy.getRequestClient().getClient();
+ }
+
+ private HttpClientContext getContext() {
+ return Proxy.getRequestClient().getContext();
}
}