|
From: <mgu...@us...> - 2012-11-08 09:04:07
|
Revision: 7702
http://sourceforge.net/p/htmlunit/code/7702
Author: mguillem
Date: 2012-11-08 09:03:45 +0000 (Thu, 08 Nov 2012)
Log Message:
-----------
removed unchecked cast
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2012-11-08 05:08:19 UTC (rev 7701)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2012-11-08 09:03:45 UTC (rev 7702)
@@ -373,9 +373,8 @@
public boolean clearExpired(final Date date) {
return false;
}
- @SuppressWarnings("unchecked")
public List<Cookie> getCookies() {
- return Collections.EMPTY_LIST;
+ return Collections.<Cookie>emptyList();
}
});
}
|
|
From: <asa...@us...> - 2012-12-03 03:33:04
|
Revision: 7816
http://sourceforge.net/p/htmlunit/code/7816
Author: asashour
Date: 2012-12-03 03:32:32 +0000 (Mon, 03 Dec 2012)
Log Message:
-----------
WebClient.closeAllWindows() to delete all temporary created big files: make the list null afterwards.
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2012-12-01 13:34:43 UTC (rev 7815)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2012-12-03 03:32:32 UTC (rev 7816)
@@ -742,6 +742,7 @@
for (final File file : temporaryFiles_) {
file.delete();
}
+ temporaryFiles_ = null;
}
}
}
|
|
From: <mgu...@us...> - 2013-01-07 11:32:39
|
Revision: 7940
http://sourceforge.net/p/htmlunit/code/7940
Author: mguillem
Date: 2013-01-07 11:32:36 +0000 (Mon, 07 Jan 2013)
Log Message:
-----------
discard HttpClient instance in case of Error as workaround for leak with connections
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-01-07 07:42:55 UTC (rev 7939)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-01-07 11:32:36 UTC (rev 7940)
@@ -181,6 +181,16 @@
throw s;
}
}
+ catch (final Error e) {
+ // in case a StackOverflowError occurs while the connection is leased, it won't get released.
+ // Calling code may catch the StackOverflowError, but due to the leak, the httpClient_ may
+ // come out of connections and throw a ConnectionPoolTimeoutException.
+ // => best solution, discard the HttpClient instance.
+ synchronized (this) {
+ httpClient_ = null;
+ }
+ throw e;
+ }
final DownloadedContent downloadedBody = downloadResponseBody(httpResponse);
final long endTime = System.currentTimeMillis();
|
|
From: <asa...@us...> - 2013-09-15 12:35:17
|
Revision: 8484
http://sourceforge.net/p/htmlunit/code/8484
Author: asashour
Date: 2013-09-15 12:35:14 +0000 (Sun, 15 Sep 2013)
Log Message:
-----------
cleanup
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-09-15 12:25:46 UTC (rev 8483)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-09-15 12:35:14 UTC (rev 8484)
@@ -287,13 +287,6 @@
}
}
else if (FormEncodingType.MULTIPART == webRequest.getEncodingType()) {
- final StringBuilder boundary = new StringBuilder();
- boundary.append("---------------------------");
- final Random rand = new Random();
- final char[] chars = "-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
- for (int i = 0; i < 14; i++) {
- boundary.append(chars[rand.nextInt(chars.length)]);
- }
final Charset c = getCharset(charset, webRequest.getRequestParameters());
final MultipartEntityBuilder builder = MultipartEntityBuilder.create().setLaxMode();
builder.setCharset(c);
|
|
From: <rb...@us...> - 2013-09-15 16:07:28
|
Revision: 8488
http://sourceforge.net/p/htmlunit/code/8488
Author: rbri
Date: 2013-09-15 16:07:25 +0000 (Sun, 15 Sep 2013)
Log Message:
-----------
import fix
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-09-15 15:42:15 UTC (rev 8487)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-09-15 16:07:25 UTC (rev 8488)
@@ -37,7 +37,6 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
-import java.util.Random;
import javax.net.ssl.SSLPeerUnverifiedException;
|
|
From: <asa...@us...> - 2014-01-26 07:19:11
|
Revision: 9065
http://sourceforge.net/p/htmlunit/code/9065
Author: asashour
Date: 2014-01-26 07:19:07 +0000 (Sun, 26 Jan 2014)
Log Message:
-----------
HttpWebConnection: virtual host
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-01-26 06:40:25 UTC (rev 9064)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-01-26 07:19:07 UTC (rev 9065)
@@ -225,9 +225,7 @@
*/
private static HttpHost getHostConfiguration(final WebRequest webRequest) {
final URL url = webRequest.getUrl();
- final HttpHost hostConfiguration = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
-
- return hostConfiguration;
+ return new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
}
// private static void setProxy(final HttpUriRequest httpUriRequest, final WebRequest webRequest) {
@@ -285,6 +283,9 @@
// what shouldn't happen here
URI uri = URIUtils.createURI(url.getProtocol(), url.getHost(), url.getPort(), url.getPath(),
escapeQuery(url.getQuery()), null);
+ if (getVirtualHost() != null) {
+ uri = URI.create(getVirtualHost());
+ }
final HttpRequestBase httpMethod = buildHttpMethod(webRequest.getHttpMethod(), uri);
setProxy(httpMethod, webRequest);
if (!(httpMethod instanceof HttpEntityEnclosingRequest)) {
@@ -392,8 +393,6 @@
if (webClient_.getCookieManager().isCookiesEnabled()) {
// Cookies are enabled. Note that it's important that we enable single cookie headers,
// for compatibility purposes.
- // TODO: asashour
-// httpClient.getParams().setParameter(CookieSpecPNames.SINGLE_COOKIE_HEADER, Boolean.TRUE);
httpClient.setDefaultCookieStore(new HtmlUnitCookieStore(webClient_.getCookieManager()));
}
else {
@@ -579,37 +578,6 @@
* @return the <tt>HttpClient</tt> that will be used by this WebConnection
*/
protected HttpClientBuilder createHttpClient() {
- // TODO: asashour
-// final HttpParams httpParams = new BasicHttpParams();
-//
-// HttpClientParams.setRedirecting(httpParams, false);
-// // Set timeouts
-// configureTimeout(httpParams, webClient_.getOptions().getTimeout());
-//
-// final SchemeRegistry schemeRegistry = new SchemeRegistry();
-// schemeRegistry.register(new Scheme("http", 80, new SocksSocketFactory()));
-// configureHttpsScheme(schemeRegistry);
-//
-// final PoolingClientConnectionManager connectionManager =
-// new PoolingClientConnectionManager(schemeRegistry);
-// connectionManager.setDefaultMaxPerRoute(6);
-//
-// final DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, httpParams);
-// httpClient.setCookieStore(new HtmlUnitCookieStore2(webClient_.getCookieManager()));
-//
-// httpClient.setRedirectStrategy(new DefaultRedirectStrategy() {
-// @Override
-// public boolean isRedirected(final HttpRequest request, final HttpResponse response,
-// final HttpContext context) throws ProtocolException {
-// return super.isRedirected(request, response, context)
-// && response.getFirstHeader("location") != null;
-// }
-// });
-//
-// if (getVirtualHost() != null) {
-// httpClient.getParams().setParameter(ClientPNames.VIRTUAL_HOST, virtualHost_);
-// }
-
final HttpClientBuilder builder = HttpClientBuilder.create();
builder.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
@@ -684,10 +652,6 @@
*/
public void setVirtualHost(final String virtualHost) {
virtualHost_ = virtualHost;
- if (virtualHost_ != null) {
- // TODO: asashour
- //getHttpClient().getParams().setParameter(ClientPNames.VIRTUAL_HOST, virtualHost_);
- }
}
/**
|
|
From: <rb...@us...> - 2014-03-09 16:26:11
|
Revision: 9170
http://sourceforge.net/p/htmlunit/code/9170
Author: rbri
Date: 2014-03-09 16:26:08 +0000 (Sun, 09 Mar 2014)
Log Message:
-----------
try to cleanup the code, always do the configuration in the same order
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-08 22:01:16 UTC (rev 9169)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-09 16:26:08 UTC (rev 9170)
@@ -133,10 +133,10 @@
private final WebClient webClient_;
/** Use single HttpContext, so there is no need to re-send authentication for each and every request. */
- private HttpContext httpContext_ = new HttpClientContext();
+ private final HttpContext httpContext_;
private String virtualHost_;
private final CookieSpecProvider htmlUnitCookieSpecProvider_;
- private final WebClientOptions usedOptions_ = new WebClientOptions();
+ private final WebClientOptions usedOptions_;
/**
* Creates a new HTTP web connection instance.
@@ -150,6 +150,8 @@
return new HtmlUnitBrowserCompatCookieSpec(webClient_.getIncorrectnessListener());
}
};
+ httpContext_ = new HttpClientContext();
+ usedOptions_ = new WebClientOptions();
}
/**
@@ -386,10 +388,9 @@
credentialsProvider.setCredentials(authScope, requestCredentials);
httpContext_.removeAttribute(HttpClientContext.TARGET_AUTH_STATE);
}
+ httpClient.setDefaultCredentialsProvider(credentialsProvider);
httpContext_.removeAttribute(HttpClientContext.CREDS_PROVIDER);
- httpClient.setDefaultCredentialsProvider(credentialsProvider);
- httpContext_.removeAttribute(HttpClientContext.COOKIE_STORE);
if (webClient_.getCookieManager().isCookiesEnabled()) {
// Cookies are enabled. Note that it's important that we enable single cookie headers,
// for compatibility purposes.
@@ -408,6 +409,8 @@
}
});
}
+ httpContext_.removeAttribute(HttpClientContext.COOKIE_STORE);
+
return httpMethod;
}
|
|
From: <asa...@us...> - 2014-03-11 22:19:30
|
Revision: 9174
http://sourceforge.net/p/htmlunit/code/9174
Author: asashour
Date: 2014-03-11 22:19:27 +0000 (Tue, 11 Mar 2014)
Log Message:
-----------
HttpWebConnection: use the same context, when calling SSLv3, thanks to Ronald for hinting.
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-11 17:37:56 UTC (rev 9173)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-11 22:19:27 UTC (rev 9174)
@@ -184,7 +184,7 @@
// Try to use only SSLv3 instead
if (webClient_.getOptions().isUseInsecureSSL()) {
HtmlUnitSSLConnectionSocketFactory.setUseSSL3Only(httpContext_, true);
- httpResponse = builder.build().execute(hostConfiguration, httpMethod);
+ httpResponse = builder.build().execute(hostConfiguration, httpMethod, httpContext_);
}
else {
throw s;
|
|
From: <asa...@us...> - 2014-03-22 05:18:32
|
Revision: 9202
http://sourceforge.net/p/htmlunit/code/9202
Author: asashour
Date: 2014-03-22 05:18:28 +0000 (Sat, 22 Mar 2014)
Log Message:
-----------
checkstyle
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-22 05:00:14 UTC (rev 9201)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-22 05:18:28 UTC (rev 9202)
@@ -910,7 +910,8 @@
*/
final class HtmlUnitHttpClientBuilder {
- private static PoolingHttpClientConnectionManager poolingmgr;
+ private static PoolingHttpClientConnectionManager POOLING_CONNECTION_MANAGER_;
+
private HtmlUnitHttpClientBuilder() {
}
@@ -919,8 +920,8 @@
* <code>socketFactory</code>.
*/
public static void configureConnectionManager(final HttpClientBuilder builder) {
- if (poolingmgr != null) {
- builder.setConnectionManager(poolingmgr);
+ if (POOLING_CONNECTION_MANAGER_ != null) {
+ builder.setConnectionManager(POOLING_CONNECTION_MANAGER_);
return;
}
final ConnectionSocketFactory socketFactory = new SocksConnectionSocketFactory();
@@ -962,33 +963,33 @@
}
}
- poolingmgr = new PoolingHttpClientConnectionManager(
+ POOLING_CONNECTION_MANAGER_ = new PoolingHttpClientConnectionManager(
RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", socketFactory)
.register("https", sslSocketFactory)
.build());
if (defaultSocketConfig != null) {
- poolingmgr.setDefaultSocketConfig(defaultSocketConfig);
+ POOLING_CONNECTION_MANAGER_.setDefaultSocketConfig(defaultSocketConfig);
}
if (defaultConnectionConfig != null) {
- poolingmgr.setDefaultConnectionConfig(defaultConnectionConfig);
+ POOLING_CONNECTION_MANAGER_.setDefaultConnectionConfig(defaultConnectionConfig);
}
if (systemProperties) {
String s = System.getProperty("http.keepAlive", "true");
if ("true".equalsIgnoreCase(s)) {
s = System.getProperty("http.maxConnections", "5");
final int max = Integer.parseInt(s);
- poolingmgr.setDefaultMaxPerRoute(max);
- poolingmgr.setMaxTotal(2 * max);
+ POOLING_CONNECTION_MANAGER_.setDefaultMaxPerRoute(max);
+ POOLING_CONNECTION_MANAGER_.setMaxTotal(2 * max);
}
}
if (maxConnTotal > 0) {
- poolingmgr.setMaxTotal(maxConnTotal);
+ POOLING_CONNECTION_MANAGER_.setMaxTotal(maxConnTotal);
}
if (maxConnPerRoute > 0) {
- poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
+ POOLING_CONNECTION_MANAGER_.setDefaultMaxPerRoute(maxConnPerRoute);
}
- builder.setConnectionManager(poolingmgr);
+ builder.setConnectionManager(POOLING_CONNECTION_MANAGER_);
}
private static String[] split(final String s) {
|
|
From: <asa...@us...> - 2014-03-25 19:28:50
|
Revision: 9204
http://sourceforge.net/p/htmlunit/code/9204
Author: asashour
Date: 2014-03-25 19:28:46 +0000 (Tue, 25 Mar 2014)
Log Message:
-----------
HttpWebConnection: fix last change done for the connection manager
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-25 19:14:53 UTC (rev 9203)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-03-25 19:28:46 UTC (rev 9204)
@@ -137,6 +137,7 @@
private String virtualHost_;
private final CookieSpecProvider htmlUnitCookieSpecProvider_;
private final WebClientOptions usedOptions_;
+ private PoolingHttpClientConnectionManager connectionManager_;
/**
* Creates a new HTTP web connection instance.
@@ -161,7 +162,10 @@
final URL url = request.getUrl();
final HttpClientBuilder builder = reconfigureHttpClientIfNeeded(getHttpClientBuilder());
- HtmlUnitHttpClientBuilder.configureConnectionManager(builder);
+ if (connectionManager_ == null) {
+ connectionManager_ = HtmlUnitHttpClientBuilder.createConnectionManager(builder);
+ }
+ builder.setConnectionManager(connectionManager_);
HttpUriRequest httpMethod = null;
try {
@@ -910,8 +914,6 @@
*/
final class HtmlUnitHttpClientBuilder {
- private static PoolingHttpClientConnectionManager POOLING_CONNECTION_MANAGER_;
-
private HtmlUnitHttpClientBuilder() {
}
@@ -919,11 +921,7 @@
* Has the exact logic in HttpClientBuilder, but with the ability to configure
* <code>socketFactory</code>.
*/
- public static void configureConnectionManager(final HttpClientBuilder builder) {
- if (POOLING_CONNECTION_MANAGER_ != null) {
- builder.setConnectionManager(POOLING_CONNECTION_MANAGER_);
- return;
- }
+ public static PoolingHttpClientConnectionManager createConnectionManager(final HttpClientBuilder builder) {
final ConnectionSocketFactory socketFactory = new SocksConnectionSocketFactory();
LayeredConnectionSocketFactory sslSocketFactory =
@@ -963,33 +961,33 @@
}
}
- POOLING_CONNECTION_MANAGER_ = new PoolingHttpClientConnectionManager(
+ final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(
RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", socketFactory)
.register("https", sslSocketFactory)
.build());
if (defaultSocketConfig != null) {
- POOLING_CONNECTION_MANAGER_.setDefaultSocketConfig(defaultSocketConfig);
+ connectionManager.setDefaultSocketConfig(defaultSocketConfig);
}
if (defaultConnectionConfig != null) {
- POOLING_CONNECTION_MANAGER_.setDefaultConnectionConfig(defaultConnectionConfig);
+ connectionManager.setDefaultConnectionConfig(defaultConnectionConfig);
}
if (systemProperties) {
String s = System.getProperty("http.keepAlive", "true");
if ("true".equalsIgnoreCase(s)) {
s = System.getProperty("http.maxConnections", "5");
final int max = Integer.parseInt(s);
- POOLING_CONNECTION_MANAGER_.setDefaultMaxPerRoute(max);
- POOLING_CONNECTION_MANAGER_.setMaxTotal(2 * max);
+ connectionManager.setDefaultMaxPerRoute(max);
+ connectionManager.setMaxTotal(2 * max);
}
}
if (maxConnTotal > 0) {
- POOLING_CONNECTION_MANAGER_.setMaxTotal(maxConnTotal);
+ connectionManager.setMaxTotal(maxConnTotal);
}
if (maxConnPerRoute > 0) {
- POOLING_CONNECTION_MANAGER_.setDefaultMaxPerRoute(maxConnPerRoute);
+ connectionManager.setDefaultMaxPerRoute(maxConnPerRoute);
}
- builder.setConnectionManager(POOLING_CONNECTION_MANAGER_);
+ return connectionManager;
}
private static String[] split(final String s) {
|
|
From: <rb...@us...> - 2014-04-06 12:35:05
|
Revision: 9234
http://sourceforge.net/p/htmlunit/code/9234
Author: rbri
Date: 2014-04-06 12:35:00 +0000 (Sun, 06 Apr 2014)
Log Message:
-----------
code cleanup
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-05 18:12:41 UTC (rev 9233)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-06 12:35:00 UTC (rev 9234)
@@ -224,7 +224,7 @@
private void setProxy(final HttpRequestBase httpRequest, final WebRequest webRequest) {
final RequestConfig.Builder requestBuilder = createRequestConfig();
- configureTimeout(requestBuilder, webClient_.getOptions().getTimeout());
+ configureTimeout(requestBuilder, getTimeout());
if (webRequest.getProxyHost() != null) {
final HttpHost proxy = new HttpHost(webRequest.getProxyHost(), webRequest.getProxyPort());
@@ -550,7 +550,7 @@
&& response.getFirstHeader("location") != null;
}
});
- configureTimeout(builder, webClient_.getOptions().getTimeout());
+ configureTimeout(builder, getTimeout());
builder.setMaxConnPerRoute(6);
return builder;
}
@@ -590,8 +590,9 @@
configureHttpsScheme(httpClientBuilder);
}
- if (options.getTimeout() != usedOptions_.getTimeout()) {
- configureTimeout(httpClientBuilder, options.getTimeout());
+ final int timeout = getTimeout();
+ if (timeout != usedOptions_.getTimeout()) {
+ configureTimeout(httpClientBuilder, timeout);
}
return httpClientBuilder;
}
|
|
From: <rb...@us...> - 2014-04-09 17:27:14
|
Revision: 9239
http://sourceforge.net/p/htmlunit/code/9239
Author: rbri
Date: 2014-04-09 17:27:09 +0000 (Wed, 09 Apr 2014)
Log Message:
-----------
try to cleanup the code a bit
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-08 16:23:46 UTC (rev 9238)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-09 17:27:09 UTC (rev 9239)
@@ -223,8 +223,7 @@
}
private void setProxy(final HttpRequestBase httpRequest, final WebRequest webRequest) {
- final RequestConfig.Builder requestBuilder = createRequestConfig();
- configureTimeout(requestBuilder, getTimeout());
+ final RequestConfig.Builder requestBuilder = createRequestConfigBuilder(getTimeout());
if (webRequest.getProxyHost() != null) {
final HttpHost proxy = new HttpHost(webRequest.getProxyHost(), webRequest.getProxyPort());
@@ -556,27 +555,25 @@
}
private void configureTimeout(final HttpClientBuilder builder, final int timeout) {
- final RequestConfig.Builder requestBuilder = createRequestConfig();
- configureTimeout(requestBuilder, timeout);
+ final RequestConfig.Builder requestBuilder = createRequestConfigBuilder(timeout);
builder.setDefaultRequestConfig(requestBuilder.build());
httpContext_.removeAttribute(HttpClientContext.REQUEST_CONFIG);
usedOptions_.setTimeout(timeout);
}
- private RequestConfig.Builder createRequestConfig() {
+ private RequestConfig.Builder createRequestConfigBuilder(final int timeout) {
final RequestConfig.Builder requestBuilder = RequestConfig.custom()
.setCookieSpec(HACKED_COOKIE_POLICY)
- .setRedirectsEnabled(false);
+ .setRedirectsEnabled(false)
+
+ // timeout
+ .setConnectTimeout(timeout)
+ .setConnectionRequestTimeout(timeout)
+ .setSocketTimeout(timeout);
return requestBuilder;
}
- private void configureTimeout(final RequestConfig.Builder builder, final int timeout) {
- builder.setConnectTimeout(timeout)
- .setConnectionRequestTimeout(timeout)
- .setSocketTimeout(timeout);
- }
-
/**
* React on changes that may have occurred on the WebClient settings.
* Registering as a listener would be probably better.
|
|
From: <rb...@us...> - 2014-04-09 18:39:55
|
Revision: 9240
http://sourceforge.net/p/htmlunit/code/9240
Author: rbri
Date: 2014-04-09 18:39:49 +0000 (Wed, 09 Apr 2014)
Log Message:
-----------
try to simplify the code a bit
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-09 17:27:09 UTC (rev 9239)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-09 18:39:49 UTC (rev 9240)
@@ -25,7 +25,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
-import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -43,6 +42,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
@@ -94,7 +94,6 @@
import org.apache.http.impl.cookie.RFC2965SpecFactory;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HttpContext;
-import org.apache.http.util.TextUtils;
import com.gargoylesoftware.htmlunit.util.KeyDataPair;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
@@ -151,7 +150,7 @@
final HttpClientBuilder builder = reconfigureHttpClientIfNeeded(getHttpClientBuilder());
if (connectionManager_ == null) {
- connectionManager_ = HtmlUnitHttpClientBuilder.createConnectionManager(builder);
+ connectionManager_ = createConnectionManager(builder);
}
builder.setConnectionManager(connectionManager_);
@@ -727,6 +726,87 @@
httpClientBuilder_ = null;
}
}
+
+ /**
+ * Has the exact logic in HttpClientBuilder, but with the ability to configure
+ * <code>socketFactory</code>.
+ */
+ private PoolingHttpClientConnectionManager createConnectionManager(final HttpClientBuilder builder) {
+ final ConnectionSocketFactory socketFactory = new SocksConnectionSocketFactory();
+
+ LayeredConnectionSocketFactory sslSocketFactory;
+ try {
+ sslSocketFactory = (LayeredConnectionSocketFactory)
+ FieldUtils.readDeclaredField(builder, "sslSocketFactory", true);
+ final SocketConfig defaultSocketConfig = (SocketConfig)
+ FieldUtils.readDeclaredField(builder, "defaultSocketConfig", true);
+ final ConnectionConfig defaultConnectionConfig = (ConnectionConfig)
+ FieldUtils.readDeclaredField(builder, "defaultConnectionConfig", true);
+ final boolean systemProperties = (Boolean) FieldUtils.readDeclaredField(builder, "systemProperties", true);
+ final int maxConnTotal = (Integer) FieldUtils.readDeclaredField(builder, "maxConnTotal", true);
+ final int maxConnPerRoute = (Integer) FieldUtils.readDeclaredField(builder, "maxConnPerRoute", true);
+ X509HostnameVerifier hostnameVerifier = (X509HostnameVerifier)
+ FieldUtils.readDeclaredField(builder, "hostnameVerifier", true);
+ final SSLContext sslcontext = (SSLContext) FieldUtils.readDeclaredField(builder, "sslcontext", true);
+
+ if (sslSocketFactory == null) {
+ final String[] supportedProtocols = systemProperties
+ ? StringUtils.split(System.getProperty("https.protocols"), ',') : null;
+ final String[] supportedCipherSuites = systemProperties
+ ? StringUtils.split(System.getProperty("https.cipherSuites"), ',') : null;
+ if (hostnameVerifier == null) {
+ hostnameVerifier = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
+ }
+ if (sslcontext != null) {
+ sslSocketFactory = new SSLConnectionSocketFactory(
+ sslcontext, supportedProtocols, supportedCipherSuites, hostnameVerifier);
+ }
+ else {
+ if (systemProperties) {
+ sslSocketFactory = new SSLConnectionSocketFactory(
+ (SSLSocketFactory) SSLSocketFactory.getDefault(),
+ supportedProtocols, supportedCipherSuites, hostnameVerifier);
+ }
+ else {
+ sslSocketFactory = new SSLConnectionSocketFactory(
+ SSLContexts.createDefault(),
+ hostnameVerifier);
+ }
+ }
+ }
+
+ final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(
+ RegistryBuilder.<ConnectionSocketFactory>create()
+ .register("http", socketFactory)
+ .register("https", sslSocketFactory)
+ .build());
+ if (defaultSocketConfig != null) {
+ connectionManager.setDefaultSocketConfig(defaultSocketConfig);
+ }
+ if (defaultConnectionConfig != null) {
+ connectionManager.setDefaultConnectionConfig(defaultConnectionConfig);
+ }
+ if (systemProperties) {
+ String s = System.getProperty("http.keepAlive", "true");
+ if ("true".equalsIgnoreCase(s)) {
+ s = System.getProperty("http.maxConnections", "5");
+ final int max = Integer.parseInt(s);
+ connectionManager.setDefaultMaxPerRoute(max);
+ connectionManager.setMaxTotal(2 * max);
+ }
+ }
+ if (maxConnTotal > 0) {
+ connectionManager.setMaxTotal(maxConnTotal);
+ }
+ if (maxConnPerRoute > 0) {
+ connectionManager.setDefaultMaxPerRoute(maxConnPerRoute);
+ }
+ return connectionManager;
+ }
+ catch (final IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
/**
@@ -771,107 +851,4 @@
public synchronized void clear() {
manager_.clearCookies();
}
-
}
-
-/**
- * A helper class for configuring {@link HttpClientBuilder}.
- *
- * @author Ahmed Ashour
- */
-final class HtmlUnitHttpClientBuilder {
-
- private HtmlUnitHttpClientBuilder() {
- }
-
- /**
- * Has the exact logic in HttpClientBuilder, but with the ability to configure
- * <code>socketFactory</code>.
- */
- public static PoolingHttpClientConnectionManager createConnectionManager(final HttpClientBuilder builder) {
- final ConnectionSocketFactory socketFactory = new SocksConnectionSocketFactory();
-
- LayeredConnectionSocketFactory sslSocketFactory =
- (LayeredConnectionSocketFactory) getField(builder, "sslSocketFactory");
- final SocketConfig defaultSocketConfig = (SocketConfig) getField(builder, "defaultSocketConfig");
- final ConnectionConfig defaultConnectionConfig =
- (ConnectionConfig) getField(builder, "defaultConnectionConfig");
- final boolean systemProperties = (Boolean) getField(builder, "systemProperties");
- final int maxConnTotal = (Integer) getField(builder, "maxConnTotal");
- final int maxConnPerRoute = (Integer) getField(builder, "maxConnPerRoute");
- X509HostnameVerifier hostnameVerifier = (X509HostnameVerifier) getField(builder, "hostnameVerifier");
- final SSLContext sslcontext = (SSLContext) getField(builder, "sslcontext");
-
- if (sslSocketFactory == null) {
- final String[] supportedProtocols = systemProperties ? split(
- System.getProperty("https.protocols")) : null;
- final String[] supportedCipherSuites = systemProperties ? split(
- System.getProperty("https.cipherSuites")) : null;
- if (hostnameVerifier == null) {
- hostnameVerifier = SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
- }
- if (sslcontext != null) {
- sslSocketFactory = new SSLConnectionSocketFactory(
- sslcontext, supportedProtocols, supportedCipherSuites, hostnameVerifier);
- }
- else {
- if (systemProperties) {
- sslSocketFactory = new SSLConnectionSocketFactory(
- (SSLSocketFactory) SSLSocketFactory.getDefault(),
- supportedProtocols, supportedCipherSuites, hostnameVerifier);
- }
- else {
- sslSocketFactory = new SSLConnectionSocketFactory(
- SSLContexts.createDefault(),
- hostnameVerifier);
- }
- }
- }
-
- final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(
- RegistryBuilder.<ConnectionSocketFactory>create()
- .register("http", socketFactory)
- .register("https", sslSocketFactory)
- .build());
- if (defaultSocketConfig != null) {
- connectionManager.setDefaultSocketConfig(defaultSocketConfig);
- }
- if (defaultConnectionConfig != null) {
- connectionManager.setDefaultConnectionConfig(defaultConnectionConfig);
- }
- if (systemProperties) {
- String s = System.getProperty("http.keepAlive", "true");
- if ("true".equalsIgnoreCase(s)) {
- s = System.getProperty("http.maxConnections", "5");
- final int max = Integer.parseInt(s);
- connectionManager.setDefaultMaxPerRoute(max);
- connectionManager.setMaxTotal(2 * max);
- }
- }
- if (maxConnTotal > 0) {
- connectionManager.setMaxTotal(maxConnTotal);
- }
- if (maxConnPerRoute > 0) {
- connectionManager.setDefaultMaxPerRoute(maxConnPerRoute);
- }
- return connectionManager;
- }
-
- private static String[] split(final String s) {
- if (TextUtils.isBlank(s)) {
- return null;
- }
- return s.split(" *, *");
- }
-
- private static Object getField(final HttpClientBuilder builder, final String fieldName) {
- try {
- final Field field = HttpClientBuilder.class.getDeclaredField(fieldName);
- field.setAccessible(true);
- return field.get(builder);
- }
- catch (final Exception e) {
- throw new RuntimeException(e);
- }
- }
-}
|
|
From: <rb...@us...> - 2014-04-20 14:59:37
|
Revision: 9297
http://sourceforge.net/p/htmlunit/code/9297
Author: rbri
Date: 2014-04-20 14:59:34 +0000 (Sun, 20 Apr 2014)
Log Message:
-----------
minor code optimization
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-20 13:49:59 UTC (rev 9296)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-04-20 14:59:34 UTC (rev 9297)
@@ -251,13 +251,14 @@
private HttpUriRequest makeHttpMethod(final WebRequest webRequest)
throws IOException, URISyntaxException {
+ final String charset = webRequest.getCharset();
+
// Make sure that the URL is fully encoded. IE actually sends some Unicode chars in request
// URLs; because of this we allow some Unicode chars in URLs. However, at this point we're
// handing things over the HttpClient, and HttpClient will blow up if we leave these Unicode
// chars in the URL.
- final URL url = UrlUtils.encodeUrl(webRequest.getUrl(), false, webRequest.getCharset());
+ final URL url = UrlUtils.encodeUrl(webRequest.getUrl(), false, charset);
- final String charset = webRequest.getCharset();
// URIUtils.createURI is deprecated but as of httpclient-4.2.1, URIBuilder doesn't work here as it encodes path
// what shouldn't happen here
URI uri = URIUtils.createURI(url.getProtocol(), url.getHost(), url.getPort(), url.getPath(),
@@ -308,7 +309,7 @@
}
else {
builder.addTextBody(pair.getName(), pair.getValue(),
- ContentType.create("text/plain", webRequest.getCharset()));
+ ContentType.create("text/plain", charset));
}
}
method.setEntity(builder.build());
|
|
From: <rb...@us...> - 2014-05-27 20:22:34
|
Revision: 9393
http://sourceforge.net/p/htmlunit/code/9393
Author: rbri
Date: 2014-05-27 20:22:29 +0000 (Tue, 27 May 2014)
Log Message:
-----------
try to fix the failing local maven build on some windows machines (com.gargoylesoftware.htmlunit.html.HtmlFileInputTest.testUploadFileWithNonASCIIName())
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-05-27 17:42:23 UTC (rev 9392)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-05-27 20:22:29 UTC (rev 9393)
@@ -444,7 +444,6 @@
else {
filename = pairWithFile.getFile().getName();
}
- filename = new String(filename.getBytes(pairWithFile.getCharset()));
builder.addBinaryBody(pairWithFile.getName(), pairWithFile.getFile(), contentType, filename);
}
|
|
From: <asa...@us...> - 2014-05-28 13:35:45
|
Revision: 9394
http://sourceforge.net/p/htmlunit/code/9394
Author: asashour
Date: 2014-05-28 13:35:40 +0000 (Wed, 28 May 2014)
Log Message:
-----------
HttpWebConnection: shutdown the connection pool.
Issue 1577
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-05-27 20:22:29 UTC (rev 9393)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-05-28 13:35:40 UTC (rev 9394)
@@ -734,6 +734,9 @@
if (httpClientBuilder_ != null) {
httpClientBuilder_ = null;
}
+ if (connectionManager_ != null) {
+ connectionManager_.shutdown();
+ }
}
/**
|
|
From: <rb...@us...> - 2014-05-28 19:14:52
|
Revision: 9399
http://sourceforge.net/p/htmlunit/code/9399
Author: rbri
Date: 2014-05-28 19:14:49 +0000 (Wed, 28 May 2014)
Log Message:
-----------
fix connection shutdown (1577)
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-05-28 19:06:28 UTC (rev 9398)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-05-28 19:14:49 UTC (rev 9399)
@@ -736,6 +736,7 @@
}
if (connectionManager_ != null) {
connectionManager_.shutdown();
+ connectionManager_ = null;
}
}
|
|
From: <asa...@us...> - 2014-08-22 08:15:52
|
Revision: 9635
http://sourceforge.net/p/htmlunit/code/9635
Author: asashour
Date: 2014-08-22 08:15:45 +0000 (Fri, 22 Aug 2014)
Log Message:
-----------
Fixing the build
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-08-22 07:28:39 UTC (rev 9634)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-08-22 08:15:45 UTC (rev 9635)
@@ -752,29 +752,35 @@
}
final String userAgent = webClient_.getBrowserVersion().getUserAgent();
- for (final String header : webClient_.getBrowserVersion().getHeaderNamesOrdered()) {
- if ("Host".equals(header)) {
- httpMethod.setHeader(new BasicHeader(header, host.toString()));
+ final String[] headerNames = webClient_.getBrowserVersion().getHeaderNamesOrdered();
+ if (headerNames != null) {
+ for (final String header : headerNames) {
+ if ("Host".equals(header)) {
+ httpMethod.setHeader(new BasicHeader(header, host.toString()));
+ }
+ else if ("User-Agent".equals(header)) {
+ httpMethod.setHeader(new BasicHeader(header, userAgent));
+ }
+ else if ("Accept".equals(header) && requestHeaders.get(header) != null) {
+ httpMethod.setHeader(new BasicHeader(header, requestHeaders.get(header)));
+ }
+ else if ("Accept-Language".equals(header) && requestHeaders.get(header) != null) {
+ httpMethod.setHeader(new BasicHeader(header, requestHeaders.get(header)));
+ }
+ else if ("Accept-Encoding".equals(header) && requestHeaders.get(header) != null) {
+ httpMethod.setHeader(new BasicHeader(header, requestHeaders.get(header)));
+ }
+ else if ("Connection".equals(header) && requestHeaders.get(header) != null) {
+ httpMethod.setHeader(new BasicHeader(header, requestHeaders.get(header)));
+ }
+ else if ("DNT".equals(header) && webClient_.getOptions().isDoNotTrackEnabled()) {
+ httpMethod.setHeader(new BasicHeader(header, "1"));
+ }
}
- else if ("User-Agent".equals(header)) {
- httpMethod.setHeader(new BasicHeader(header, userAgent));
- }
- else if ("Accept".equals(header) && requestHeaders.get(header) != null) {
- httpMethod.setHeader(new BasicHeader(header, requestHeaders.get(header)));
- }
- else if ("Accept-Language".equals(header) && requestHeaders.get(header) != null) {
- httpMethod.setHeader(new BasicHeader(header, requestHeaders.get(header)));
- }
- else if ("Accept-Encoding".equals(header) && requestHeaders.get(header) != null) {
- httpMethod.setHeader(new BasicHeader(header, requestHeaders.get(header)));
- }
- else if ("Connection".equals(header) && requestHeaders.get(header) != null) {
- httpMethod.setHeader(new BasicHeader(header, requestHeaders.get(header)));
- }
- else if ("DNT".equals(header) && webClient_.getOptions().isDoNotTrackEnabled()) {
- httpMethod.setHeader(new BasicHeader(header, "1"));
- }
}
+ else {
+ httpMethod.setHeader(new BasicHeader("User-Agent", userAgent));
+ }
// not all browser versions have DNT by default as part of getHeaderNamesOrdered()
// so we add it again, in case
|
|
From: <asa...@us...> - 2014-08-25 09:11:06
|
Revision: 9650
http://sourceforge.net/p/htmlunit/code/9650
Author: asashour
Date: 2014-08-25 09:10:58 +0000 (Mon, 25 Aug 2014)
Log Message:
-----------
Fixing build: specially IE8 tests
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-08-25 07:50:09 UTC (rev 9649)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2014-08-25 09:10:58 UTC (rev 9650)
@@ -820,6 +820,8 @@
}
else {
list.add(new StaticHttpRequestInterceptor("User-Agent", userAgent) { });
+ list.add(new RequestAddCookies());
+ list.add(new RequestClientConnControl());
}
// not all browser versions have DNT by default as part of getHeaderNamesOrdered()
|
|
From: <rb...@us...> - 2015-02-20 20:27:06
|
Revision: 9999
http://sourceforge.net/p/htmlunit/code/9999
Author: rbri
Date: 2015-02-20 20:27:03 +0000 (Fri, 20 Feb 2015)
Log Message:
-----------
remove some warnings
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-02-20 19:04:35 UTC (rev 9998)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-02-20 20:27:03 UTC (rev 9999)
@@ -103,10 +103,10 @@
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.impl.cookie.BestMatchSpecFactory;
import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
-import org.apache.http.impl.cookie.IgnoreSpecFactory;
-import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
-import org.apache.http.impl.cookie.RFC2109SpecFactory;
-import org.apache.http.impl.cookie.RFC2965SpecFactory;
+import org.apache.http.impl.cookie.IgnoreSpecProvider;
+import org.apache.http.impl.cookie.NetscapeDraftSpecProvider;
+import org.apache.http.impl.cookie.RFC2109SpecProvider;
+import org.apache.http.impl.cookie.RFC2965SpecProvider;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessorBuilder;
import org.apache.http.protocol.RequestContent;
@@ -509,12 +509,12 @@
final RegistryBuilder<CookieSpecProvider> registeryBuilder
= RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
- .register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
+ .register(CookieSpecs.STANDARD, new RFC2965SpecProvider())
.register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
- .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
- .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory())
- .register("rfc2109", new RFC2109SpecFactory())
- .register("rfc2965", new RFC2965SpecFactory());
+ .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
+ .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider())
+ .register("rfc2109", new RFC2109SpecProvider())
+ .register("rfc2965", new RFC2965SpecProvider());
registeryBuilder.register(HACKED_COOKIE_POLICY, htmlUnitCookieSpecProvider_);
httpClientBuilder_.setDefaultCookieSpecRegistry(registeryBuilder.build());
|
|
From: <asa...@us...> - 2015-06-05 14:51:05
|
Revision: 10644
http://sourceforge.net/p/htmlunit/code/10644
Author: asashour
Date: 2015-06-05 14:51:03 +0000 (Fri, 05 Jun 2015)
Log Message:
-----------
Fixing build
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-05 13:05:20 UTC (rev 10643)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-05 14:51:03 UTC (rev 10644)
@@ -875,7 +875,7 @@
final int maxConnPerRoute = (Integer) FieldUtils.readDeclaredField(builder, "maxConnPerRoute", true);
HostnameVerifier hostnameVerifier = (HostnameVerifier)
FieldUtils.readDeclaredField(builder, "hostnameVerifier", true);
- final SSLContext sslcontext = (SSLContext) FieldUtils.readDeclaredField(builder, "sslcontext", true);
+ final SSLContext sslcontext = (SSLContext) FieldUtils.readDeclaredField(builder, "sslContext", true);
if (sslSocketFactory == null) {
final String[] supportedProtocols = systemProperties
|
|
From: <rb...@us...> - 2015-06-17 18:20:30
|
Revision: 10738
http://sourceforge.net/p/htmlunit/code/10738
Author: rbri
Date: 2015-06-17 18:20:27 +0000 (Wed, 17 Jun 2015)
Log Message:
-----------
refactoring: do not ask a second time for the builder i we already have created one
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-17 18:05:47 UTC (rev 10737)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-17 18:20:27 UTC (rev 10738)
@@ -163,7 +163,7 @@
HttpUriRequest httpMethod = null;
try {
try {
- httpMethod = makeHttpMethod(request);
+ httpMethod = makeHttpMethod(request, builder);
}
catch (final URISyntaxException e) {
throw new IOException("Unable to create URI from URL: " + url.toExternalForm()
@@ -246,12 +246,13 @@
/**
* Creates an <tt>HttpMethod</tt> instance according to the specified parameters.
* @param webRequest the request
+ * @param httpClientBuilder the httpClientBuilder that will be configured
* @return the <tt>HttpMethod</tt> instance constructed according to the specified parameters
* @throws IOException
* @throws URISyntaxException
*/
@SuppressWarnings("deprecation")
- private HttpUriRequest makeHttpMethod(final WebRequest webRequest)
+ private HttpUriRequest makeHttpMethod(final WebRequest webRequest, final HttpClientBuilder httpClientBuilder)
throws IOException, URISyntaxException {
final String charset = webRequest.getCharset();
@@ -325,10 +326,8 @@
}
}
- final HttpClientBuilder httpClient = getHttpClientBuilder();
+ configureHttpProcessorBuilder(httpClientBuilder, webRequest);
- configureHttpProcessor(httpClient, webRequest);
-
// Tell the client where to get its credentials from
// (it may have changed on the webClient since last call to getHttpClientFor(...))
final CredentialsProvider credentialsProvider = webClient_.getCredentialsProvider();
@@ -353,7 +352,7 @@
credentialsProvider.setCredentials(authScope, requestCredentials);
httpContext_.removeAttribute(HttpClientContext.TARGET_AUTH_STATE);
}
- httpClient.setDefaultCredentialsProvider(credentialsProvider);
+ httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
httpContext_.removeAttribute(HttpClientContext.CREDS_PROVIDER);
return httpMethod;
@@ -602,7 +601,7 @@
usedOptions_.setProxyConfig(options.getProxyConfig());
}
- private void configureHttpProcessor(final HttpClientBuilder builder, final WebRequest webRequest)
+ private void configureHttpProcessorBuilder(final HttpClientBuilder builder, final WebRequest webRequest)
throws IOException {
final HttpProcessorBuilder b = HttpProcessorBuilder.create();
for (final HttpRequestInterceptor i : getHttpRequestInterceptors(webRequest)) {
|
|
From: <rb...@us...> - 2015-06-17 19:11:46
|
Revision: 10739
http://sourceforge.net/p/htmlunit/code/10739
Author: rbri
Date: 2015-06-17 19:11:44 +0000 (Wed, 17 Jun 2015)
Log Message:
-----------
revert some changed, it seems to be more complicated
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-17 18:20:27 UTC (rev 10738)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-17 19:11:44 UTC (rev 10739)
@@ -83,6 +83,7 @@
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
@@ -96,7 +97,7 @@
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.ssl.SSLContexts;
-import com.gargoylesoftware.htmlunit.httpclient.HtmlUnitCookieSpecProvider;
+import com.gargoylesoftware.htmlunit.httpclient.HtmlUnitBrowserCompatCookieSpec;
import com.gargoylesoftware.htmlunit.httpclient.HtmlUnitCookieStore;
import com.gargoylesoftware.htmlunit.httpclient.HtmlUnitRedirectStrategie;
import com.gargoylesoftware.htmlunit.httpclient.HtmlUnitSSLConnectionSocketFactory;
@@ -143,7 +144,12 @@
*/
public HttpWebConnection(final WebClient webClient) {
webClient_ = webClient;
- htmlUnitCookieSpecProvider_ = new HtmlUnitCookieSpecProvider(webClient.getBrowserVersion());
+ htmlUnitCookieSpecProvider_ = new CookieSpecProvider() {
+ @Override
+ public CookieSpec create(final HttpContext context) {
+ return new HtmlUnitBrowserCompatCookieSpec(webClient.getBrowserVersion());
+ }
+ };
httpContext_ = new HttpClientContext();
usedOptions_ = new WebClientOptions();
}
@@ -163,7 +169,7 @@
HttpUriRequest httpMethod = null;
try {
try {
- httpMethod = makeHttpMethod(request, builder);
+ httpMethod = makeHttpMethod(request);
}
catch (final URISyntaxException e) {
throw new IOException("Unable to create URI from URL: " + url.toExternalForm()
@@ -246,13 +252,12 @@
/**
* Creates an <tt>HttpMethod</tt> instance according to the specified parameters.
* @param webRequest the request
- * @param httpClientBuilder the httpClientBuilder that will be configured
* @return the <tt>HttpMethod</tt> instance constructed according to the specified parameters
* @throws IOException
* @throws URISyntaxException
*/
@SuppressWarnings("deprecation")
- private HttpUriRequest makeHttpMethod(final WebRequest webRequest, final HttpClientBuilder httpClientBuilder)
+ private HttpUriRequest makeHttpMethod(final WebRequest webRequest)
throws IOException, URISyntaxException {
final String charset = webRequest.getCharset();
@@ -326,8 +331,10 @@
}
}
- configureHttpProcessorBuilder(httpClientBuilder, webRequest);
+ final HttpClientBuilder httpClient = getHttpClientBuilder();
+ configureHttpProcessor(httpClient, webRequest);
+
// Tell the client where to get its credentials from
// (it may have changed on the webClient since last call to getHttpClientFor(...))
final CredentialsProvider credentialsProvider = webClient_.getCredentialsProvider();
@@ -352,7 +359,7 @@
credentialsProvider.setCredentials(authScope, requestCredentials);
httpContext_.removeAttribute(HttpClientContext.TARGET_AUTH_STATE);
}
- httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
+ httpClient.setDefaultCredentialsProvider(credentialsProvider);
httpContext_.removeAttribute(HttpClientContext.CREDS_PROVIDER);
return httpMethod;
@@ -512,12 +519,12 @@
}
/**
- * Creates the <tt>HttpClientBuilder</tt> that will be used by this WebClient.
+ * Creates the <tt>HttpClient</tt> that will be used by this WebClient.
* Extensions may override this method in order to create a customized
- * <tt>HttpClientBuilder</tt> instance (e.g. with a custom
+ * <tt>HttpClient</tt> instance (e.g. with a custom
* {@link org.apache.http.conn.ClientConnectionManager} to perform
* some tracking; see feature request 1438216).
- * @return the <tt>HttpClientBuilder</tt> that will be used by this WebConnection
+ * @return the <tt>HttpClient</tt> that will be used by this WebConnection
*/
protected HttpClientBuilder createHttpClient() {
final HttpClientBuilder builder = HttpClientBuilder.create();
@@ -601,7 +608,7 @@
usedOptions_.setProxyConfig(options.getProxyConfig());
}
- private void configureHttpProcessorBuilder(final HttpClientBuilder builder, final WebRequest webRequest)
+ private void configureHttpProcessor(final HttpClientBuilder builder, final WebRequest webRequest)
throws IOException {
final HttpProcessorBuilder b = HttpProcessorBuilder.create();
for (final HttpRequestInterceptor i : getHttpRequestInterceptors(webRequest)) {
|
|
From: <rb...@us...> - 2015-06-29 19:47:53
|
Revision: 10807
http://sourceforge.net/p/htmlunit/code/10807
Author: rbri
Date: 2015-06-29 19:47:51 +0000 (Mon, 29 Jun 2015)
Log Message:
-----------
create instance of a static class instead of anonymous inner classes to reduce memory usage
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-29 16:20:42 UTC (rev 10806)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-29 19:47:51 UTC (rev 10807)
@@ -754,22 +754,22 @@
if (headerNames != null) {
for (final String header : headerNames) {
if ("Host".equals(header)) {
- list.add(new StaticHttpRequestInterceptor(header, host.toString()) { });
+ list.add(new StaticHttpRequestInterceptor(header, host.toString()));
}
else if ("User-Agent".equals(header)) {
- list.add(new StaticHttpRequestInterceptor(header, userAgent) { });
+ list.add(new StaticHttpRequestInterceptor(header, userAgent));
}
else if ("Accept".equals(header) && requestHeaders.get(header) != null) {
- list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)) { });
+ list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)));
}
else if ("Accept-Language".equals(header) && requestHeaders.get(header) != null) {
- list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)) { });
+ list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)));
}
else if ("Accept-Encoding".equals(header) && requestHeaders.get(header) != null) {
- list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)) { });
+ list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)));
}
else if ("Referer".equals(header) && requestHeaders.get(header) != null) {
- list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)) { });
+ list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)));
}
else if ("Connection".equals(header)) {
list.add(new RequestClientConnControl());
@@ -778,12 +778,12 @@
list.add(new RequestAddCookies());
}
else if ("DNT".equals(header) && webClient_.getOptions().isDoNotTrackEnabled()) {
- list.add(new StaticHttpRequestInterceptor(header, "1") { });
+ list.add(new StaticHttpRequestInterceptor(header, "1"));
}
}
}
else {
- list.add(new StaticHttpRequestInterceptor("User-Agent", userAgent) { });
+ list.add(new StaticHttpRequestInterceptor("User-Agent", userAgent));
list.add(new RequestAddCookies());
list.add(new RequestClientConnControl());
}
@@ -791,7 +791,7 @@
// not all browser versions have DNT by default as part of getHeaderNamesOrdered()
// so we add it again, in case
if (webClient_.getOptions().isDoNotTrackEnabled()) {
- list.add(new StaticHttpRequestInterceptor("DNT", "1") { });
+ list.add(new StaticHttpRequestInterceptor("DNT", "1"));
}
synchronized (requestHeaders) {
@@ -801,13 +801,13 @@
}
/** We must have a separate class per header, because of org.apache.http.protocol.ChainBuilder. */
- private abstract static class StaticHttpRequestInterceptor implements HttpRequestInterceptor {
+ private static final class StaticHttpRequestInterceptor implements HttpRequestInterceptor {
private String name_;
private String value_;
StaticHttpRequestInterceptor(final String name, final String value) {
- this.name_ = name;
- this.value_ = value;
+ name_ = name;
+ value_ = value;
}
@Override
@@ -817,11 +817,11 @@
}
}
- private static class MultiHttpRequestInterceptor implements HttpRequestInterceptor {
+ private static final class MultiHttpRequestInterceptor implements HttpRequestInterceptor {
private final Map<String, String> map_;
MultiHttpRequestInterceptor(final Map<String, String> map) {
- this.map_ = map;
+ map_ = map;
}
@Override
|
|
From: <rb...@us...> - 2015-06-29 20:37:08
|
Revision: 10808
http://sourceforge.net/p/htmlunit/code/10808
Author: rbri
Date: 2015-06-29 20:37:06 +0000 (Mon, 29 Jun 2015)
Log Message:
-----------
revert last change, needs more analysis
Modified Paths:
--------------
trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-29 19:47:51 UTC (rev 10807)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2015-06-29 20:37:06 UTC (rev 10808)
@@ -754,22 +754,22 @@
if (headerNames != null) {
for (final String header : headerNames) {
if ("Host".equals(header)) {
- list.add(new StaticHttpRequestInterceptor(header, host.toString()));
+ list.add(new StaticHttpRequestInterceptor(header, host.toString()) { });
}
else if ("User-Agent".equals(header)) {
- list.add(new StaticHttpRequestInterceptor(header, userAgent));
+ list.add(new StaticHttpRequestInterceptor(header, userAgent) { });
}
else if ("Accept".equals(header) && requestHeaders.get(header) != null) {
- list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)));
+ list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)) { });
}
else if ("Accept-Language".equals(header) && requestHeaders.get(header) != null) {
- list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)));
+ list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)) { });
}
else if ("Accept-Encoding".equals(header) && requestHeaders.get(header) != null) {
- list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)));
+ list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)) { });
}
else if ("Referer".equals(header) && requestHeaders.get(header) != null) {
- list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)));
+ list.add(new StaticHttpRequestInterceptor(header, requestHeaders.get(header)) { });
}
else if ("Connection".equals(header)) {
list.add(new RequestClientConnControl());
@@ -778,12 +778,12 @@
list.add(new RequestAddCookies());
}
else if ("DNT".equals(header) && webClient_.getOptions().isDoNotTrackEnabled()) {
- list.add(new StaticHttpRequestInterceptor(header, "1"));
+ list.add(new StaticHttpRequestInterceptor(header, "1") { });
}
}
}
else {
- list.add(new StaticHttpRequestInterceptor("User-Agent", userAgent));
+ list.add(new StaticHttpRequestInterceptor("User-Agent", userAgent) { });
list.add(new RequestAddCookies());
list.add(new RequestClientConnControl());
}
@@ -791,7 +791,7 @@
// not all browser versions have DNT by default as part of getHeaderNamesOrdered()
// so we add it again, in case
if (webClient_.getOptions().isDoNotTrackEnabled()) {
- list.add(new StaticHttpRequestInterceptor("DNT", "1"));
+ list.add(new StaticHttpRequestInterceptor("DNT", "1") { });
}
synchronized (requestHeaders) {
@@ -801,13 +801,13 @@
}
/** We must have a separate class per header, because of org.apache.http.protocol.ChainBuilder. */
- private static final class StaticHttpRequestInterceptor implements HttpRequestInterceptor {
+ private abstract static class StaticHttpRequestInterceptor implements HttpRequestInterceptor {
private String name_;
private String value_;
StaticHttpRequestInterceptor(final String name, final String value) {
- name_ = name;
- value_ = value;
+ this.name_ = name;
+ this.value_ = value;
}
@Override
@@ -817,11 +817,11 @@
}
}
- private static final class MultiHttpRequestInterceptor implements HttpRequestInterceptor {
+ private static class MultiHttpRequestInterceptor implements HttpRequestInterceptor {
private final Map<String, String> map_;
MultiHttpRequestInterceptor(final Map<String, String> map) {
- map_ = map;
+ this.map_ = map;
}
@Override
|