|
27 | 27 | import java.util.ServiceConfigurationError; |
28 | 28 | import java.util.ServiceLoader; |
29 | 29 | import java.util.concurrent.TimeoutException; |
| 30 | + |
| 31 | +import org.apache.http.HttpEntity; |
30 | 32 | import org.apache.http.HttpHost; |
31 | 33 | import org.apache.http.HttpResponse; |
32 | 34 | import org.apache.http.HttpStatus; |
33 | 35 | import org.apache.http.client.HttpClient; |
| 36 | +import org.apache.http.client.config.RequestConfig; |
34 | 37 | import org.apache.http.client.methods.HttpGet; |
35 | 38 | import org.apache.http.client.methods.HttpPost; |
36 | 39 | import org.apache.http.client.utils.URIUtils; |
| 40 | +import org.apache.http.entity.BufferedHttpEntity; |
37 | 41 | import org.apache.http.entity.ContentType; |
38 | 42 | import org.apache.http.entity.StringEntity; |
| 43 | +import org.apache.http.impl.client.CloseableHttpClient; |
39 | 44 | import org.apache.http.impl.client.HttpClientBuilder; |
40 | 45 | import org.openqa.selenium.Capabilities; |
41 | 46 | import org.openqa.selenium.MutableCapabilities; |
@@ -93,9 +98,22 @@ public static boolean isHostActive(final URL hostUrl, final String... pathAndPar |
93 | 98 | */ |
94 | 99 | public static HttpResponse getHttpResponse(final URL hostUrl, final String... pathAndParams) throws IOException { |
95 | 100 | Objects.requireNonNull(hostUrl, "[hostUrl] must be non-null"); |
96 | | - HttpClient client = HttpClientBuilder.create().build(); |
| 101 | + |
97 | 102 | URI uri = UriUtils.makeBasicURI(hostUrl.getProtocol(), hostUrl.getHost(), hostUrl.getPort(), pathAndParams); |
98 | | - return client.execute(extractHost(hostUrl), new HttpGet(uri.toURL().toExternalForm())); |
| 103 | + |
| 104 | + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(2000) |
| 105 | + .setConnectionRequestTimeout(2000).setSocketTimeout(5000).build(); |
| 106 | + CloseableHttpClient client = HttpClientBuilder.create().disableAutomaticRetries() |
| 107 | + .setDefaultRequestConfig(requestConfig).build(); |
| 108 | + |
| 109 | + HttpGet request = new HttpGet(uri.toString()); |
| 110 | + HttpResponse response = client.execute(extractHost(hostUrl), request); |
| 111 | + HttpEntity entity = response.getEntity(); |
| 112 | + if (entity != null && entity.isStreaming()) { |
| 113 | + response.setEntity(new BufferedHttpEntity(entity)); |
| 114 | + } |
| 115 | + |
| 116 | + return response; |
99 | 117 | } |
100 | 118 |
|
101 | 119 | /** |
|
0 commit comments