diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java b/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java
index dec40d252..b1c630124 100644
--- a/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java
+++ b/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java
@@ -31,9 +31,9 @@ import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
@@ -46,13 +46,14 @@ import org.apache.http.util.EntityUtils;
public class ClientExecuteProxy {
public static void main(String[] args)throws Exception {
- HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http");
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
- httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
-
HttpHost target = new HttpHost("issues.apache.org", 443, "https");
+ HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http");
+
+ RequestConfig config = RequestConfig.custom().setDefaultProxy(proxy).build();
HttpGet request = new HttpGet("/");
+ request.setConfig(config);
System.out.println("executing request to " + target + " via " + proxy);
CloseableHttpResponse response = httpclient.execute(target, request);
diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java
index 6fc8c7074..6d64d2092 100644
--- a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java
+++ b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveBasicAuthentication.java
@@ -33,14 +33,12 @@ import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;
/**
diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java
index 9e858a204..cf27d68ca 100644
--- a/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java
+++ b/httpclient/src/examples/org/apache/http/examples/client/ClientPreemptiveDigestAuthentication.java
@@ -33,14 +33,12 @@ import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.auth.DigestScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;
/**
diff --git a/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java b/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java
index 1bcdfeea0..f8f650557 100644
--- a/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java
+++ b/httpclient/src/examples/org/apache/http/examples/client/ClientProxyAuthentication.java
@@ -30,9 +30,9 @@ import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
@@ -55,9 +55,9 @@ public class ClientProxyAuthentication {
HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https");
HttpHost proxy = new HttpHost("localhost", 8080);
- httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
-
+ RequestConfig config = RequestConfig.custom().setDefaultProxy(proxy).build();
HttpGet httpget = new HttpGet("/");
+ httpget.setConfig(config);
System.out.println("executing request: " + httpget.getRequestLine());
System.out.println("via proxy: " + proxy);
diff --git a/httpclient/src/main/java/org/apache/http/auth/params/AuthPNames.java b/httpclient/src/main/java/org/apache/http/auth/params/AuthPNames.java
index b54c8bfa6..1bae4ffbf 100644
--- a/httpclient/src/main/java/org/apache/http/auth/params/AuthPNames.java
+++ b/httpclient/src/main/java/org/apache/http/auth/params/AuthPNames.java
@@ -28,12 +28,18 @@
package org.apache.http.auth.params;
import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.client.config.RequestConfig;
/**
* Parameter names for HTTP authentication classes.
*
* @since 4.0
- */
+ *
+ * @deprecated (4.3) use {@link RequestConfig} and constructor parameters of
+ * {@link AuthSchemeProvider}s.
+*/
+@Deprecated
public interface AuthPNames {
/**
diff --git a/httpclient/src/main/java/org/apache/http/auth/params/AuthParamBean.java b/httpclient/src/main/java/org/apache/http/auth/params/AuthParamBean.java
index 0d759142d..57a6c12a4 100644
--- a/httpclient/src/main/java/org/apache/http/auth/params/AuthParamBean.java
+++ b/httpclient/src/main/java/org/apache/http/auth/params/AuthParamBean.java
@@ -27,6 +27,8 @@
package org.apache.http.auth.params;
+import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.params.HttpAbstractParamBean;
import org.apache.http.params.HttpParams;
@@ -36,7 +38,11 @@ import org.apache.http.params.HttpParams;
* using Java Beans conventions.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link RequestConfig} and constructor parameters of
+ * {@link AuthSchemeProvider}s.
*/
+@Deprecated
public class AuthParamBean extends HttpAbstractParamBean {
public AuthParamBean (final HttpParams params) {
diff --git a/httpclient/src/main/java/org/apache/http/auth/params/AuthParams.java b/httpclient/src/main/java/org/apache/http/auth/params/AuthParams.java
index 8e8250a0e..0223ca7fa 100644
--- a/httpclient/src/main/java/org/apache/http/auth/params/AuthParams.java
+++ b/httpclient/src/main/java/org/apache/http/auth/params/AuthParams.java
@@ -28,6 +28,8 @@
package org.apache.http.auth.params;
import org.apache.http.annotation.Immutable;
+import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
@@ -38,9 +40,11 @@ import org.apache.http.protocol.HTTP;
*
* @since 4.0
*
- * @see AuthPNames
+ * @deprecated (4.3) use {@link RequestConfig} and constructor parameters of
+ * {@link AuthSchemeProvider}s.
*/
@Immutable
+@Deprecated
public final class AuthParams {
private AuthParams() {
diff --git a/httpclient/src/main/java/org/apache/http/client/config/AuthSchemes.java b/httpclient/src/main/java/org/apache/http/client/config/AuthSchemes.java
new file mode 100644
index 000000000..3b6d803f7
--- /dev/null
+++ b/httpclient/src/main/java/org/apache/http/client/config/AuthSchemes.java
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.http.client.config;
+
+import org.apache.http.annotation.Immutable;
+
+/**
+ * Standard authentication schemes supported by HttpClient.
+ *
+ * @since 4.3
+ */
+@Immutable
+public final class AuthSchemes {
+
+ /**
+ * Basic authentication scheme as defined in RFC2617 (considered inherently
+ * insecure, but most widely supported)
+ */
+ public static final String BASIC = "Basic";
+
+ /**
+ * Digest authentication scheme as defined in RFC2617.
+ */
+ public static final String DIGEST = "Digest";
+
+ /**
+ * The NTLM scheme is a proprietary Microsoft Windows Authentication
+ * protocol (considered to be the most secure among currently supported
+ * authentication schemes).
+ */
+ public static final String NTLM = "NTLM";
+
+ /**
+ * SPNEGO Authentication scheme.
+ */
+ public static final String SPNEGO = "negotiate";
+
+ /**
+ * Kerberos Authentication scheme.
+ */
+ public static final String KERBEROS = "Kerberos";
+
+ private AuthSchemes() {
+ }
+
+}
diff --git a/httpclient/src/main/java/org/apache/http/client/config/CookieSpecs.java b/httpclient/src/main/java/org/apache/http/client/config/CookieSpecs.java
new file mode 100644
index 000000000..9158c1b2f
--- /dev/null
+++ b/httpclient/src/main/java/org/apache/http/client/config/CookieSpecs.java
@@ -0,0 +1,74 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.http.client.config;
+
+import org.apache.http.annotation.Immutable;
+
+/**
+ * Standard cookie specifications supported by HttpClient.
+ *
+ * @since 4.3
+ */
+@Immutable
+public final class CookieSpecs {
+
+ /**
+ * The policy that provides high degree of compatibility
+ * with common cookie management of popular HTTP agents.
+ */
+ public static final String BROWSER_COMPATIBILITY = "compatibility";
+
+ /**
+ * The Netscape cookie draft compliant policy.
+ */
+ public static final String NETSCAPE = "netscape";
+
+ /**
+ * The RFC 2109 compliant policy.
+ */
+ public static final String RFC_2109 = "rfc2109";
+
+ /**
+ * The RFC 2965 compliant policy.
+ */
+ public static final String RFC_2965 = "rfc2965";
+
+ /**
+ * The default 'best match' policy.
+ */
+ public static final String BEST_MATCH = "best-match";
+
+ /**
+ * The policy that ignores cookies.
+ */
+ public static final String IGNORE_COOKIES = "ignoreCookies";
+
+ private CookieSpecs() {
+ }
+
+}
diff --git a/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java b/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java
new file mode 100644
index 000000000..83a95a6a5
--- /dev/null
+++ b/httpclient/src/main/java/org/apache/http/client/config/RequestConfig.java
@@ -0,0 +1,306 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.http.client.config;
+
+import java.net.InetAddress;
+import java.util.Collection;
+
+import org.apache.http.HttpHost;
+
+public class RequestConfig implements Cloneable {
+
+ public static final RequestConfig DEFAULT = new Builder().build();
+
+ private final boolean expectContinueEnabled;
+ private final HttpHost defaultProxy;
+ private final InetAddress localAddress;
+ private final boolean staleConnectionCheckEnabled;
+ private final String cookieSpec;
+ private final boolean redirectsEnabled;
+ private final boolean relativeRedirectsAllowed;
+ private final boolean circularRedirectsAllowed;
+ private final int maxRedirects;
+ private final boolean authenticationEnabled;
+ private final Collection targetPreferredAuthSchemes;
+ private final Collection proxyPreferredAuthSchemes;
+ private final int connectionRequestTimeout;
+ private final int connectTimeout;
+ private final int socketTimeout;
+
+ RequestConfig(
+ final boolean expectContinueEnabled,
+ final HttpHost defaultProxy,
+ final InetAddress localAddress,
+ final boolean staleConnectionCheckEnabled,
+ final String cookieSpec,
+ final boolean redirectsEnabled,
+ final boolean relativeRedirectsAllowed,
+ final boolean circularRedirectsAllowed,
+ final int maxRedirects,
+ final boolean authenticationEnabled,
+ final Collection targetPreferredAuthSchemes,
+ final Collection proxyPreferredAuthSchemes,
+ final int connectionRequestTimeout,
+ final int connectTimeout,
+ final int socketTimeout) {
+ super();
+ this.expectContinueEnabled = expectContinueEnabled;
+ this.defaultProxy = defaultProxy;
+ this.localAddress = localAddress;
+ this.staleConnectionCheckEnabled = staleConnectionCheckEnabled;
+ this.cookieSpec = cookieSpec;
+ this.redirectsEnabled = redirectsEnabled;
+ this.relativeRedirectsAllowed = relativeRedirectsAllowed;
+ this.circularRedirectsAllowed = circularRedirectsAllowed;
+ this.maxRedirects = maxRedirects;
+ this.authenticationEnabled = authenticationEnabled;
+ this.targetPreferredAuthSchemes = targetPreferredAuthSchemes;
+ this.proxyPreferredAuthSchemes = proxyPreferredAuthSchemes;
+ this.connectionRequestTimeout = connectionRequestTimeout;
+ this.connectTimeout = connectTimeout;
+ this.socketTimeout = socketTimeout;
+ }
+
+ public boolean isExpectContinueEnabled() {
+ return expectContinueEnabled;
+ }
+
+ public HttpHost getDefaultProxy() {
+ return defaultProxy;
+ }
+
+ public InetAddress getLocalAddress() {
+ return localAddress;
+ }
+
+ public boolean isStaleConnectionCheckEnabled() {
+ return staleConnectionCheckEnabled;
+ }
+
+ public String getCookieSpec() {
+ return cookieSpec;
+ }
+
+ public boolean isRedirectsEnabled() {
+ return redirectsEnabled;
+ }
+
+ public boolean isRelativeRedirectsAllowed() {
+ return relativeRedirectsAllowed;
+ }
+
+ public boolean isCircularRedirectsAllowed() {
+ return circularRedirectsAllowed;
+ }
+
+ public int getMaxRedirects() {
+ return maxRedirects;
+ }
+
+ public boolean isAuthenticationEnabled() {
+ return authenticationEnabled;
+ }
+
+ public Collection getTargetPreferredAuthSchemes() {
+ return targetPreferredAuthSchemes;
+ }
+
+ public Collection getProxyPreferredAuthSchemes() {
+ return proxyPreferredAuthSchemes;
+ }
+
+ public int getConnectionRequestTimeout() {
+ return connectionRequestTimeout;
+ }
+
+ public int getConnectTimeout() {
+ return connectTimeout;
+ }
+
+ public int getSocketTimeout() {
+ return socketTimeout;
+ }
+
+ @Override
+ protected RequestConfig clone() throws CloneNotSupportedException {
+ return (RequestConfig) super.clone();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append(", expectContinueEnabled=").append(expectContinueEnabled);
+ builder.append(", defaultProxy=").append(defaultProxy);
+ builder.append(", localAddress=").append(localAddress);
+ builder.append(", staleConnectionCheckEnabled=").append(staleConnectionCheckEnabled);
+ builder.append(", cookieSpec=").append(cookieSpec);
+ builder.append(", redirectsEnabled=").append(redirectsEnabled);
+ builder.append(", relativeRedirectsAllowed=").append(relativeRedirectsAllowed);
+ builder.append(", maxRedirects=").append(maxRedirects);
+ builder.append(", circularRedirectsAllowed=").append(circularRedirectsAllowed);
+ builder.append(", authenticationEnabled=").append(authenticationEnabled);
+ builder.append(", targetPreferredAuthSchemes=").append(targetPreferredAuthSchemes);
+ builder.append(", proxyPreferredAuthSchemes=").append(proxyPreferredAuthSchemes);
+ builder.append(", connectionRequestTimeout=").append(connectionRequestTimeout);
+ builder.append(", connectTimeout=").append(connectTimeout);
+ builder.append(", socketTimeout=").append(socketTimeout);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ public static RequestConfig.Builder custom() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private boolean expectContinueEnabled;
+ private HttpHost defaultProxy;
+ private InetAddress localAddress;
+ private boolean staleConnectionCheckEnabled;
+ private String cookieSpec;
+ private boolean redirectsEnabled;
+ private boolean relativeRedirectsAllowed;
+ private boolean circularRedirectsAllowed;
+ private int maxRedirects;
+ private boolean authenticationEnabled;
+ private Collection targetPreferredAuthSchemes;
+ private Collection proxyPreferredAuthSchemes;
+ private int connectionRequestTimeout;
+ private int connectTimeout;
+ private int socketTimeout;
+
+ Builder() {
+ super();
+ this.staleConnectionCheckEnabled = true;
+ this.redirectsEnabled = true;
+ this.maxRedirects = 50;
+ this.relativeRedirectsAllowed = true;
+ this.authenticationEnabled = true;
+ this.connectionRequestTimeout = -1;
+ this.connectTimeout = -1;
+ this.socketTimeout = -1;
+ }
+
+ public Builder setExpectContinueEnabled(boolean expectContinueEnabled) {
+ this.expectContinueEnabled = expectContinueEnabled;
+ return this;
+ }
+
+ public Builder setDefaultProxy(final HttpHost defaultProxy) {
+ this.defaultProxy = defaultProxy;
+ return this;
+ }
+
+ public Builder setLocalAddress(final InetAddress localAddress) {
+ this.localAddress = localAddress;
+ return this;
+ }
+
+ public Builder setStaleConnectionCheckEnabled(boolean staleConnectionCheckEnabled) {
+ this.staleConnectionCheckEnabled = staleConnectionCheckEnabled;
+ return this;
+ }
+
+ public Builder setCookieSpec(final String cookieSpec) {
+ this.cookieSpec = cookieSpec;
+ return this;
+ }
+
+ public Builder setRedirectsEnabled(boolean redirectsEnabled) {
+ this.redirectsEnabled = redirectsEnabled;
+ return this;
+ }
+
+ public Builder setRelativeRedirectsAllowed(boolean relativeRedirectsAllowed) {
+ this.relativeRedirectsAllowed = relativeRedirectsAllowed;
+ return this;
+ }
+
+ public Builder setCircularRedirectsAllowed(boolean circularRedirectsAllowed) {
+ this.circularRedirectsAllowed = circularRedirectsAllowed;
+ return this;
+ }
+
+ public Builder setMaxRedirects(final int maxRedirects) {
+ this.maxRedirects = maxRedirects;
+ return this;
+ }
+
+ public Builder setAuthenticationEnabled(boolean authenticationEnabled) {
+ this.authenticationEnabled = authenticationEnabled;
+ return this;
+ }
+
+ public Builder setTargetPreferredAuthSchemes(final Collection targetPreferredAuthSchemes) {
+ this.targetPreferredAuthSchemes = targetPreferredAuthSchemes;
+ return this;
+ }
+
+ public Builder setProxyPreferredAuthSchemes(final Collection proxyPreferredAuthSchemes) {
+ this.proxyPreferredAuthSchemes = proxyPreferredAuthSchemes;
+ return this;
+ }
+
+ public Builder setConnectionRequestTimeout(final int connectionRequestTimeout) {
+ this.connectionRequestTimeout = connectionRequestTimeout;
+ return this;
+ }
+
+ public Builder setConnectTimeout(int connectTimeout) {
+ this.connectTimeout = connectTimeout;
+ return this;
+ }
+
+ public Builder setSocketTimeout(final int socketTimeout) {
+ this.socketTimeout = socketTimeout;
+ return this;
+ }
+
+ public RequestConfig build() {
+ return new RequestConfig(
+ expectContinueEnabled,
+ defaultProxy,
+ localAddress,
+ staleConnectionCheckEnabled,
+ cookieSpec,
+ redirectsEnabled,
+ relativeRedirectsAllowed,
+ circularRedirectsAllowed,
+ maxRedirects,
+ authenticationEnabled,
+ targetPreferredAuthSchemes,
+ proxyPreferredAuthSchemes,
+ connectionRequestTimeout,
+ connectTimeout,
+ socketTimeout);
+ }
+
+ }
+
+}
diff --git a/httpclient/src/main/java/org/apache/http/client/methods/Configurable.java b/httpclient/src/main/java/org/apache/http/client/methods/Configurable.java
new file mode 100644
index 000000000..7b31a5a87
--- /dev/null
+++ b/httpclient/src/main/java/org/apache/http/client/methods/Configurable.java
@@ -0,0 +1,41 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.http.client.methods;
+
+import org.apache.http.client.config.RequestConfig;
+
+/**
+ * Configuration interface for HTTP requests.
+ *
+ * @since 4.3
+ */
+public interface Configurable {
+
+ RequestConfig getConfig();
+
+}
diff --git a/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java b/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java
index e3163ff79..1dd2fe2b6 100644
--- a/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java
+++ b/httpclient/src/main/java/org/apache/http/client/methods/HttpRequestBase.java
@@ -36,6 +36,7 @@ import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.ProtocolVersion;
import org.apache.http.RequestLine;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.utils.CloneUtils;
import org.apache.http.concurrent.Cancellable;
import org.apache.http.conn.ClientConnectionRequest;
@@ -45,15 +46,14 @@ import org.apache.http.message.BasicRequestLine;
import org.apache.http.params.HttpProtocolParams;
/**
- * Basic implementation of an HTTP request that can be modified. Methods of the
- * {@link AbortableHttpRequest} interface implemented by this class are thread safe.
+ * Base implementation of {@link HttpUriRequest}.
*
* @since 4.0
*/
@SuppressWarnings("deprecation")
@NotThreadSafe
public abstract class HttpRequestBase extends AbstractHttpMessage
- implements HttpUriRequest, HttpExecutionAware, AbortableHttpRequest, Cloneable {
+ implements HttpUriRequest, Configurable, HttpExecutionAware, AbortableHttpRequest, Cloneable {
private Lock abortLock;
private volatile boolean aborted;
@@ -61,6 +61,7 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
private ProtocolVersion version;
private URI uri;
private Cancellable cancellable;
+ private RequestConfig config;
public HttpRequestBase() {
super();
@@ -108,6 +109,14 @@ public abstract class HttpRequestBase extends AbstractHttpMessage
this.uri = uri;
}
+ public RequestConfig getConfig() {
+ return config;
+ }
+
+ public void setConfig(final RequestConfig config) {
+ this.config = config;
+ }
+
@Deprecated
public void setConnectionRequest(final ClientConnectionRequest connRequest) {
if (this.aborted) {
diff --git a/httpclient/src/main/java/org/apache/http/client/methods/HttpUriRequest.java b/httpclient/src/main/java/org/apache/http/client/methods/HttpUriRequest.java
index a9ca943b7..8d8510f44 100644
--- a/httpclient/src/main/java/org/apache/http/client/methods/HttpUriRequest.java
+++ b/httpclient/src/main/java/org/apache/http/client/methods/HttpUriRequest.java
@@ -36,8 +36,6 @@ import org.apache.http.HttpRequest;
* convenience methods to access request properties such as request URI
* and method type.
*
- *
- *
* @since 4.0
*/
public interface HttpUriRequest extends HttpRequest {
diff --git a/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java b/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
index 55cfcd5e9..bdfb53d68 100644
--- a/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
+++ b/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
@@ -36,10 +36,10 @@ import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.ProtocolVersion;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.utils.CloneUtils;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.HeaderGroup;
-import org.apache.http.params.HttpParams;
/**
* @since 4.3
@@ -52,7 +52,7 @@ public class RequestBuilder {
private URI uri;
private HeaderGroup headergroup;
private HttpEntity entity;
- private HttpParams params;
+ private RequestConfig config;
RequestBuilder(final String method) {
super();
@@ -124,7 +124,11 @@ public class RequestBuilder {
} else {
entity = null;
}
- params = request.getParams();
+ if (request instanceof Configurable) {
+ this.config = ((Configurable) request).getConfig();
+ } else {
+ this.config = null;
+ }
return this;
}
@@ -234,12 +238,12 @@ public class RequestBuilder {
return this;
}
- public HttpParams getParams() {
- return params;
+ public RequestConfig getConfig() {
+ return config;
}
- public RequestBuilder setParams(final HttpParams params) {
- this.params = params;
+ public RequestBuilder setConfig(final RequestConfig config) {
+ this.config = config;
return this;
}
@@ -264,9 +268,7 @@ public class RequestBuilder {
if (this.headergroup != null) {
result.setHeaders(this.headergroup.getAllHeaders());
}
- if (this.params != null) {
- result.setParams(this.params);
- }
+ result.setConfig(this.config);
return result;
}
diff --git a/httpclient/src/main/java/org/apache/http/client/params/AllClientPNames.java b/httpclient/src/main/java/org/apache/http/client/params/AllClientPNames.java
index 920c9b761..1901d5481 100644
--- a/httpclient/src/main/java/org/apache/http/client/params/AllClientPNames.java
+++ b/httpclient/src/main/java/org/apache/http/client/params/AllClientPNames.java
@@ -29,6 +29,7 @@ package org.apache.http.client.params;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.auth.params.AuthPNames;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.cookie.params.CookieSpecPNames;
import org.apache.http.conn.params.ConnManagerPNames;
import org.apache.http.conn.params.ConnConnectionPNames;
@@ -46,8 +47,10 @@ import org.apache.http.conn.params.ConnRoutePNames;
* in which the respective constants are actually defined.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link RequestConfig}
*/
-@SuppressWarnings("deprecation")
+@Deprecated
public interface AllClientPNames extends
CoreConnectionPNames, CoreProtocolPNames,
ClientPNames, AuthPNames, CookieSpecPNames,
diff --git a/httpclient/src/main/java/org/apache/http/client/params/AuthPolicy.java b/httpclient/src/main/java/org/apache/http/client/params/AuthPolicy.java
index 4391dcf4f..d4ddec233 100644
--- a/httpclient/src/main/java/org/apache/http/client/params/AuthPolicy.java
+++ b/httpclient/src/main/java/org/apache/http/client/params/AuthPolicy.java
@@ -28,12 +28,16 @@
package org.apache.http.client.params;
import org.apache.http.annotation.Immutable;
+import org.apache.http.client.config.AuthSchemes;
/**
* Standard authentication schemes supported by HttpClient.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link AuthSchemes}
*/
+@Deprecated
@Immutable
public final class AuthPolicy {
diff --git a/httpclient/src/main/java/org/apache/http/client/params/ClientPNames.java b/httpclient/src/main/java/org/apache/http/client/params/ClientPNames.java
index cb895a89a..d62fd5b8f 100644
--- a/httpclient/src/main/java/org/apache/http/client/params/ClientPNames.java
+++ b/httpclient/src/main/java/org/apache/http/client/params/ClientPNames.java
@@ -26,17 +26,18 @@
package org.apache.http.client.params;
+import org.apache.http.client.config.RequestConfig;
+
/**
* Parameter names for HTTP client parameters.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link RequestConfig}
*/
+@Deprecated
public interface ClientPNames {
- /**
- * @deprecated (4.2) do not use
- */
- @Deprecated
public static final String CONNECTION_MANAGER_FACTORY_CLASS_NAME = "http.connection-manager.factory-class-name";
/**
diff --git a/httpclient/src/main/java/org/apache/http/client/params/ClientParamBean.java b/httpclient/src/main/java/org/apache/http/client/params/ClientParamBean.java
index a9b1f730f..8b2d67295 100644
--- a/httpclient/src/main/java/org/apache/http/client/params/ClientParamBean.java
+++ b/httpclient/src/main/java/org/apache/http/client/params/ClientParamBean.java
@@ -30,6 +30,7 @@ package org.apache.http.client.params;
import java.util.Collection;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.Header;
import org.apache.http.HttpHost;
@@ -42,7 +43,10 @@ import org.apache.http.params.HttpParams;
* Java Beans conventions.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link RequestConfig}
*/
+@Deprecated
@NotThreadSafe
public class ClientParamBean extends HttpAbstractParamBean {
diff --git a/httpclient/src/main/java/org/apache/http/client/params/CookiePolicy.java b/httpclient/src/main/java/org/apache/http/client/params/CookiePolicy.java
index a80b81703..188d17918 100644
--- a/httpclient/src/main/java/org/apache/http/client/params/CookiePolicy.java
+++ b/httpclient/src/main/java/org/apache/http/client/params/CookiePolicy.java
@@ -28,12 +28,16 @@
package org.apache.http.client.params;
import org.apache.http.annotation.Immutable;
+import org.apache.http.client.config.CookieSpecs;
/**
* Standard cookie specifications supported by HttpClient.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link CookieSpecs}
*/
+@Deprecated
@Immutable
public final class CookiePolicy {
diff --git a/httpclient/src/main/java/org/apache/http/client/params/HttpClientParams.java b/httpclient/src/main/java/org/apache/http/client/params/HttpClientParams.java
index 84c5d4808..c1113006d 100644
--- a/httpclient/src/main/java/org/apache/http/client/params/HttpClientParams.java
+++ b/httpclient/src/main/java/org/apache/http/client/params/HttpClientParams.java
@@ -27,6 +27,7 @@
package org.apache.http.client.params;
import org.apache.http.annotation.Immutable;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@@ -35,7 +36,10 @@ import org.apache.http.params.HttpParams;
* An adaptor for manipulating HTTP client parameters in {@link HttpParams}.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link RequestConfig}
*/
+@Deprecated
@Immutable
public class HttpClientParams {
diff --git a/httpclient/src/main/java/org/apache/http/client/params/HttpParamConfig.java b/httpclient/src/main/java/org/apache/http/client/params/HttpParamConfig.java
new file mode 100644
index 000000000..89d30be65
--- /dev/null
+++ b/httpclient/src/main/java/org/apache/http/client/params/HttpParamConfig.java
@@ -0,0 +1,73 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.http.client.params;
+
+import java.util.Collection;
+
+import org.apache.http.auth.params.AuthPNames;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.conn.params.ConnRouteParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+
+/**
+ * @deprecated (4.3) provided for compatibility with {@link HttpParams}. Do not use.
+ *
+ * @since 4.3
+ */
+@Deprecated
+public final class HttpParamConfig {
+
+ private HttpParamConfig() {
+ }
+
+ @SuppressWarnings("unchecked")
+ public static RequestConfig getRequestConfig(final HttpParams params) {
+ return RequestConfig.custom()
+ .setAuthenticationEnabled(HttpClientParams.isAuthenticating(params))
+ .setCircularRedirectsAllowed(params.isParameterFalse(ClientPNames.REJECT_RELATIVE_REDIRECT))
+ .setConnectionRequestTimeout((int) HttpClientParams.getConnectionManagerTimeout(params))
+ .setConnectTimeout(HttpConnectionParams.getConnectionTimeout(params))
+ .setCookieSpec(HttpClientParams.getCookiePolicy(params))
+ .setDefaultProxy(ConnRouteParams.getDefaultProxy(params))
+ .setExpectContinueEnabled(HttpProtocolParams.useExpectContinue(params))
+ .setLocalAddress(ConnRouteParams.getLocalAddress(params))
+ .setMaxRedirects(params.getIntParameter(ClientPNames.MAX_REDIRECTS, 50))
+ .setProxyPreferredAuthSchemes((Collection) params.getParameter(
+ AuthPNames.PROXY_AUTH_PREF))
+ .setTargetPreferredAuthSchemes((Collection) params.getParameter(
+ AuthPNames.TARGET_AUTH_PREF))
+ .setRedirectsEnabled(HttpClientParams.isRedirecting(params))
+ .setRelativeRedirectsAllowed(params.isParameterTrue(ClientPNames.ALLOW_CIRCULAR_REDIRECTS))
+ .setSocketTimeout(HttpConnectionParams.getSoTimeout(params))
+ .setStaleConnectionCheckEnabled(HttpConnectionParams.isStaleCheckingEnabled(params))
+ .build();
+ }
+
+}
diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java b/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
index 970caaaba..979547144 100644
--- a/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
+++ b/httpclient/src/main/java/org/apache/http/client/protocol/ClientContext.java
@@ -125,7 +125,17 @@ public interface ClientContext {
/**
* Attribute name of a {@link org.apache.http.config.Lookup} object that represents
* the actual {@link ConnectionSocketFactory} registry.
+ *
+ * @since 4.3
*/
public static final String SOCKET_FACTORY_REGISTRY = "http.socket-factory-registry";
+ /**
+ * Attribute name of a {@link org.apache.http.client.config.RequestConfig} object that
+ * represents the actual request configuration.
+ *
+ * @since 4.3
+ */
+ public static final String REQUEST_CONFIG = "http.request-config";
+
}
diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java b/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java
index 74f9c3f9d..90c23864d 100644
--- a/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java
+++ b/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java
@@ -33,6 +33,7 @@ import org.apache.http.auth.AuthState;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Lookup;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.RouteInfo;
@@ -158,4 +159,13 @@ public class HttpClientContext extends HttpCoreContext implements ClientContext
setAttribute(USER_TOKEN, obj);
}
+ public RequestConfig getRequestConfig() {
+ RequestConfig config = getAttribute(REQUEST_CONFIG, RequestConfig.class);
+ return config != null ? config : RequestConfig.DEFAULT;
+ }
+
+ public void setRequestConfig(final RequestConfig config) {
+ setAttribute(REQUEST_CONFIG, config);
+ }
+
}
diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java b/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
index e22003bb3..ad5f7827f 100644
--- a/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
+++ b/httpclient/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
@@ -43,8 +43,9 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.CookieStore;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.client.params.HttpClientParams;
import org.apache.http.config.Lookup;
import org.apache.http.conn.routing.RouteInfo;
import org.apache.http.cookie.Cookie;
@@ -58,14 +59,6 @@ import org.apache.http.protocol.HttpContext;
* Request interceptor that matches cookies available in the current
* {@link CookieStore} to the request being executed and generates
* corresponding Cookie
request headers.
- *
- * The following parameters can be used to customize the behavior of this
- * class:
- *
- * - {@link org.apache.http.cookie.params.CookieSpecPNames#DATE_PATTERNS}
- * - {@link org.apache.http.cookie.params.CookieSpecPNames#SINGLE_COOKIE_HEADER}
- * - {@link org.apache.http.client.params.ClientPNames#COOKIE_POLICY}
- *
*
* @since 4.0
*/
@@ -122,7 +115,11 @@ public class RequestAddCookies implements HttpRequestInterceptor {
return;
}
- String policy = HttpClientParams.getCookiePolicy(request.getParams());
+ RequestConfig config = clientContext.getRequestConfig();
+ String policy = config.getCookieSpec();
+ if (policy == null) {
+ policy = CookieSpecs.BEST_MATCH;
+ }
if (this.log.isDebugEnabled()) {
this.log.debug("CookieSpec selected: " + policy);
}
diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java b/httpclient/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
index e00432540..3f35c4584 100644
--- a/httpclient/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
+++ b/httpclient/src/main/java/org/apache/http/client/protocol/RequestDefaultHeaders.java
@@ -44,11 +44,22 @@ import org.apache.http.protocol.HttpContext;
*
* @since 4.0
*/
+@SuppressWarnings("deprecation")
@Immutable
public class RequestDefaultHeaders implements HttpRequestInterceptor {
- public RequestDefaultHeaders() {
+ private final Collection extends Header> defaultHeaders;
+
+ /**
+ * @since 4.3
+ */
+ public RequestDefaultHeaders(final Collection extends Header> defaultHeaders) {
super();
+ this.defaultHeaders = defaultHeaders;
+ }
+
+ public RequestDefaultHeaders() {
+ this(null);
}
public void process(final HttpRequest request, final HttpContext context)
@@ -64,8 +75,11 @@ public class RequestDefaultHeaders implements HttpRequestInterceptor {
// Add default headers
@SuppressWarnings("unchecked")
- Collection defHeaders = (Collection) request.getParams().getParameter(
- ClientPNames.DEFAULT_HEADERS);
+ Collection extends Header> defHeaders = (Collection extends Header>)
+ request.getParams().getParameter(ClientPNames.DEFAULT_HEADERS);
+ if (defHeaders == null) {
+ defHeaders = this.defaultHeaders;
+ }
if (defHeaders != null) {
for (Header defHeader : defHeaders) {
diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/RequestExpectContinue.java b/httpclient/src/main/java/org/apache/http/client/protocol/RequestExpectContinue.java
new file mode 100644
index 000000000..47ec73ca0
--- /dev/null
+++ b/httpclient/src/main/java/org/apache/http/client/protocol/RequestExpectContinue.java
@@ -0,0 +1,82 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpVersion;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.Args;
+
+/**
+ * RequestExpectContinue is responsible for enabling the 'expect-continue'
+ * handshake by adding Expect
header.
+ *
+ * This interceptor takes into account {@link RequestConfig#isExpectContinueEnabled()}
+ * setting.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class RequestExpectContinue implements HttpRequestInterceptor {
+
+ public RequestExpectContinue() {
+ super();
+ }
+
+ public void process(final HttpRequest request, final HttpContext context)
+ throws HttpException, IOException {
+ Args.notNull(request, "HTTP request");
+
+ if (!request.containsHeader(HTTP.EXPECT_DIRECTIVE)) {
+ if (request instanceof HttpEntityEnclosingRequest) {
+ ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
+ HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
+ // Do not send the expect header if request body is known to be empty
+ if (entity != null
+ && entity.getContentLength() != 0 && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
+ HttpClientContext clientContext = HttpClientContext.adapt(context);
+ RequestConfig config = clientContext.getRequestConfig();
+ if (config.isExpectContinueEnabled()) {
+ request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/httpclient/src/main/java/org/apache/http/conn/HttpClientConnectionManager.java b/httpclient/src/main/java/org/apache/http/conn/HttpClientConnectionManager.java
index aa7bdb304..42e1b9cad 100644
--- a/httpclient/src/main/java/org/apache/http/conn/HttpClientConnectionManager.java
+++ b/httpclient/src/main/java/org/apache/http/conn/HttpClientConnectionManager.java
@@ -79,7 +79,9 @@ public interface HttpClientConnectionManager {
HttpClientConnection conn, Object newState, long validDuration, TimeUnit timeUnit);
void connect(
- HttpClientConnection conn, HttpHost host, InetAddress localAddress,
+ HttpClientConnection conn,
+ HttpHost host, InetAddress localAddress,
+ int connectTimeout,
HttpContext context) throws IOException;
void upgrade(
diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java
index c43e6d1e7..4a6927be2 100644
--- a/httpclient/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java
+++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java
@@ -32,6 +32,8 @@ import org.apache.http.impl.conn.DefaultHttpResponseParser;
* Parameter names for HTTP client connections.
*
* @since 4.0
+ *
+ * @deprecated (4.1) use custom {@link DefaultHttpResponseParser} implementation.
*/
@Deprecated
public interface ConnConnectionPNames {
@@ -53,7 +55,7 @@ public interface ConnConnectionPNames {
* Use {@link java.lang.Integer#MAX_VALUE} for unlimited number.
*
*
- * @deprecated Use custom {@link DefaultHttpResponseParser} implementation
+ * @deprecated (4.1) Use custom {@link DefaultHttpResponseParser} implementation
*/
@Deprecated
public static final String MAX_STATUS_LINE_GARBAGE = "http.connection.max-status-line-garbage";
diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java
index 375838b8d..ca7ece9e1 100644
--- a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java
+++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java
@@ -31,7 +31,7 @@ package org.apache.http.conn.params;
*
* @since 4.0
*
- * @deprecated (4.1.2) use configuration methods of the specific connection manager implementation.
+ * @deprecated (4.1) use configuration methods of the specific connection manager implementation.
*/
@Deprecated
public interface ConnManagerPNames {
diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParamBean.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParamBean.java
index 953af4923..fafb71314 100644
--- a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParamBean.java
+++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParamBean.java
@@ -39,7 +39,7 @@ import org.apache.http.params.HttpParams;
*
* @since 4.0
*
- * @deprecated (4.1.2) use configuration methods of the specific connection manager implementation.
+ * @deprecated (4.1) use configuration methods of the specific connection manager implementation.
*/
@NotThreadSafe
@Deprecated
diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParams.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParams.java
index 95725ed7f..0867f000c 100644
--- a/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParams.java
+++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnManagerParams.java
@@ -40,7 +40,7 @@ import org.apache.http.params.HttpParams;
*
* @see ConnManagerPNames
*
- * @deprecated (4.1.2) use configuration methods of the specific connection manager implementation.
+ * @deprecated (4.1) use configuration methods of the specific connection manager implementation.
*/
@Deprecated
@Immutable
diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java
index c65228781..d41980dfe 100644
--- a/httpclient/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java
+++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java
@@ -26,11 +26,16 @@
package org.apache.http.conn.params;
+import org.apache.http.client.config.RequestConfig;
+
/**
* Parameter names for connection routing.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link RequestConfig}.
*/
+@Deprecated
public interface ConnRoutePNames {
/**
diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParamBean.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParamBean.java
index 2ce172720..764002fa2 100644
--- a/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParamBean.java
+++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParamBean.java
@@ -32,6 +32,7 @@ import java.net.InetAddress;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.HttpHost;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.params.HttpAbstractParamBean;
import org.apache.http.params.HttpParams;
@@ -42,7 +43,10 @@ import org.apache.http.params.HttpParams;
* using Java Beans conventions.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link RequestConfig}.
*/
+@Deprecated
@NotThreadSafe
public class ConnRouteParamBean extends HttpAbstractParamBean {
diff --git a/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParams.java b/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParams.java
index ca12fe10a..46adb7922 100644
--- a/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParams.java
+++ b/httpclient/src/main/java/org/apache/http/conn/params/ConnRouteParams.java
@@ -32,6 +32,7 @@ import org.apache.http.annotation.Immutable;
import org.apache.http.HttpHost;
import org.apache.http.params.HttpParams;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.conn.routing.HttpRoute;
/**
@@ -39,7 +40,10 @@ import org.apache.http.conn.routing.HttpRoute;
* in {@link HttpParams}.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use {@link RequestConfig}.
*/
+@Deprecated
@Immutable
public class ConnRouteParams implements ConnRoutePNames {
diff --git a/httpclient/src/main/java/org/apache/http/cookie/params/CookieSpecPNames.java b/httpclient/src/main/java/org/apache/http/cookie/params/CookieSpecPNames.java
index 4b987395b..673bd638e 100644
--- a/httpclient/src/main/java/org/apache/http/cookie/params/CookieSpecPNames.java
+++ b/httpclient/src/main/java/org/apache/http/cookie/params/CookieSpecPNames.java
@@ -27,11 +27,16 @@
package org.apache.http.cookie.params;
+import org.apache.http.cookie.CookieSpecProvider;
+
/**
* Parameter names for HTTP cookie management classes.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use constructor parameters of {@link CookieSpecProvider}s.
*/
+@Deprecated
public interface CookieSpecPNames {
/**
diff --git a/httpclient/src/main/java/org/apache/http/cookie/params/CookieSpecParamBean.java b/httpclient/src/main/java/org/apache/http/cookie/params/CookieSpecParamBean.java
index b59c2ec5e..c787b2c23 100644
--- a/httpclient/src/main/java/org/apache/http/cookie/params/CookieSpecParamBean.java
+++ b/httpclient/src/main/java/org/apache/http/cookie/params/CookieSpecParamBean.java
@@ -30,6 +30,7 @@ package org.apache.http.cookie.params;
import java.util.Collection;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.params.HttpAbstractParamBean;
import org.apache.http.params.HttpParams;
@@ -40,7 +41,10 @@ import org.apache.http.params.HttpParams;
* conventions.
*
* @since 4.0
+ *
+ * @deprecated (4.3) use constructor parameters of {@link CookieSpecProvider}s.
*/
+@Deprecated
@NotThreadSafe
public class CookieSpecParamBean extends HttpAbstractParamBean {
diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java b/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java
index bc7233361..65284f739 100644
--- a/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java
+++ b/httpclient/src/main/java/org/apache/http/impl/auth/AuthSchemeBase.java
@@ -63,6 +63,8 @@ public abstract class AuthSchemeBase implements ContextAwareAuthScheme {
* state.
*
* @since 4.2
+ *
+ * @deprecated (4.3) do not use.
*/
public AuthSchemeBase(final ChallengeState challengeState) {
super();
@@ -70,7 +72,7 @@ public abstract class AuthSchemeBase implements ContextAwareAuthScheme {
}
public AuthSchemeBase() {
- this(null);
+ super();
}
/**
diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java b/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java
index 05349036e..335ab3d06 100644
--- a/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java
+++ b/httpclient/src/main/java/org/apache/http/impl/auth/BasicScheme.java
@@ -26,9 +26,12 @@
package org.apache.http.impl.auth;
+import java.nio.charset.Charset;
+
import org.apache.http.annotation.NotThreadSafe;
import org.apache.commons.codec.binary.Base64;
+import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.auth.AuthenticationException;
@@ -38,7 +41,6 @@ import org.apache.http.auth.Credentials;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.InvalidCredentialsException;
import org.apache.http.auth.MalformedChallengeException;
-import org.apache.http.auth.params.AuthParams;
import org.apache.http.message.BufferedHeader;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
@@ -47,12 +49,6 @@ import org.apache.http.util.EncodingUtils;
/**
* Basic authentication scheme as defined in RFC 2617.
- *
- * The following parameters can be used to customize the behavior of this
- * class:
- *
- * - {@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}
- *
*
* @since 4.0
*/
@@ -62,19 +58,29 @@ public class BasicScheme extends RFC2617Scheme {
/** Whether the basic authentication process is complete */
private boolean complete;
+ /**
+ * @since 4.3
+ */
+ public BasicScheme(final Charset credentialsCharset) {
+ super(credentialsCharset);
+ this.complete = false;
+ }
+
/**
* Creates an instance of BasicScheme with the given challenge
* state.
*
* @since 4.2
+ *
+ * @deprecated (4.3) do not use.
*/
+ @Deprecated
public BasicScheme(final ChallengeState challengeState) {
super(challengeState);
- this.complete = false;
}
public BasicScheme() {
- this(null);
+ this(Consts.ASCII);
}
/**
@@ -153,9 +159,24 @@ public class BasicScheme extends RFC2617Scheme {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
+ StringBuilder tmp = new StringBuilder();
+ tmp.append(credentials.getUserPrincipal().getName());
+ tmp.append(":");
+ tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword());
- String charset = AuthParams.getCredentialCharset(request.getParams());
- return authenticate(credentials, charset, isProxy());
+ byte[] base64password = Base64.encodeBase64(
+ EncodingUtils.getBytes(tmp.toString(), getCredentialsCharset(request)));
+
+ CharArrayBuffer buffer = new CharArrayBuffer(32);
+ if (isProxy()) {
+ buffer.append(AUTH.PROXY_AUTH_RESP);
+ } else {
+ buffer.append(AUTH.WWW_AUTH_RESP);
+ }
+ buffer.append(": Basic ");
+ buffer.append(base64password, 0, base64password.length);
+
+ return new BufferedHeader(buffer);
}
/**
@@ -166,7 +187,10 @@ public class BasicScheme extends RFC2617Scheme {
* @param charset The charset to use for encoding the credentials
*
* @return a basic authorization header
+ *
+ * @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
*/
+ @Deprecated
public static Header authenticate(
final Credentials credentials,
final String charset,
diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/BasicSchemeFactory.java b/httpclient/src/main/java/org/apache/http/impl/auth/BasicSchemeFactory.java
index d0df6a45d..afa579da6 100644
--- a/httpclient/src/main/java/org/apache/http/impl/auth/BasicSchemeFactory.java
+++ b/httpclient/src/main/java/org/apache/http/impl/auth/BasicSchemeFactory.java
@@ -27,6 +27,8 @@
package org.apache.http.impl.auth;
+import java.nio.charset.Charset;
+
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AuthScheme;
@@ -45,12 +47,26 @@ import org.apache.http.protocol.HttpContext;
@SuppressWarnings("deprecation")
public class BasicSchemeFactory implements AuthSchemeFactory, AuthSchemeProvider {
+ private final Charset charset;
+
+ /**
+ * @since 4.3
+ */
+ public BasicSchemeFactory(final Charset charset) {
+ super();
+ this.charset = charset;
+ }
+
+ public BasicSchemeFactory() {
+ this(null);
+ }
+
public AuthScheme newInstance(final HttpParams params) {
return new BasicScheme();
}
public AuthScheme create(final HttpContext context) {
- return new BasicScheme();
+ return new BasicScheme(this.charset);
}
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java b/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java
index f51c20549..443fefded 100644
--- a/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java
+++ b/httpclient/src/main/java/org/apache/http/impl/auth/DigestScheme.java
@@ -27,6 +27,7 @@
package org.apache.http.impl.auth;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.ArrayList;
@@ -39,6 +40,7 @@ import java.util.StringTokenizer;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
@@ -49,7 +51,6 @@ import org.apache.http.auth.ContextAwareAuthScheme;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.MalformedChallengeException;
-import org.apache.http.auth.params.AuthParams;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.message.BasicHeaderValueFormatter;
import org.apache.http.message.BufferedHeader;
@@ -64,22 +65,10 @@ import org.apache.http.util.EncodingUtils;
* Currently only qop=auth or no qop is supported. qop=auth-int
* is unsupported. If auth and auth-int are provided, auth is
* used.
- *
- * Credential charset is configured via the
- * {@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}
- * parameter of the HTTP request.
- *
+ *
* Since the digest username is included as clear text in the generated
* Authentication header, the charset of the username must be compatible
- * with the
- * {@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET
- * http element charset}.
- *
- * The following parameters can be used to customize the behavior of this
- * class:
- *
- * - {@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}
- *
+ * with the HTTP element charset used by the connection.
*
* @since 4.0
*/
@@ -111,19 +100,29 @@ public class DigestScheme extends RFC2617Scheme {
private String a1;
private String a2;
+ /**
+ * @since 4.3
+ */
+ public DigestScheme(final Charset credentialsCharset) {
+ super(credentialsCharset);
+ this.complete = false;
+ }
+
/**
* Creates an instance of DigestScheme with the given challenge
* state.
*
* @since 4.2
+ *
+ * @deprecated (4.3) do not use.
*/
+ @Deprecated
public DigestScheme(final ChallengeState challengeState) {
super(challengeState);
- this.complete = false;
}
public DigestScheme() {
- this(null);
+ this(Consts.ASCII);
}
/**
@@ -181,7 +180,7 @@ public class DigestScheme extends RFC2617Scheme {
/**
* @deprecated (4.2) Use {@link ContextAwareAuthScheme#authenticate(Credentials, HttpRequest, org.apache.http.protocol.HttpContext)}
*/
- @Deprecated
+ @Deprecated
public Header authenticate(
final Credentials credentials, final HttpRequest request) throws AuthenticationException {
return authenticate(credentials, request, new BasicHttpContext());
@@ -224,8 +223,7 @@ public class DigestScheme extends RFC2617Scheme {
getParameters().put("uri", request.getRequestLine().getUri());
String charset = getParameter("charset");
if (charset == null) {
- charset = AuthParams.getCredentialCharset(request.getParams());
- getParameters().put("charset", charset);
+ getParameters().put("charset", getCredentialsCharset(request));
}
return createDigestHeader(credentials, request);
}
@@ -430,7 +428,7 @@ public class DigestScheme extends RFC2617Scheme {
buffer.append(", ");
}
boolean noQuotes = "nc".equals(param.getName()) || "qop".equals(param.getName());
- BasicHeaderValueFormatter.DEFAULT.formatNameValuePair(buffer, param, !noQuotes);
+ BasicHeaderValueFormatter.INSTANCE.formatNameValuePair(buffer, param, !noQuotes);
}
return new BufferedHeader(buffer);
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/DigestSchemeFactory.java b/httpclient/src/main/java/org/apache/http/impl/auth/DigestSchemeFactory.java
index af1f72b74..e983c199a 100644
--- a/httpclient/src/main/java/org/apache/http/impl/auth/DigestSchemeFactory.java
+++ b/httpclient/src/main/java/org/apache/http/impl/auth/DigestSchemeFactory.java
@@ -27,6 +27,8 @@
package org.apache.http.impl.auth;
+import java.nio.charset.Charset;
+
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AuthScheme;
@@ -45,12 +47,26 @@ import org.apache.http.protocol.HttpContext;
@SuppressWarnings("deprecation")
public class DigestSchemeFactory implements AuthSchemeFactory, AuthSchemeProvider {
+ private final Charset charset;
+
+ /**
+ * @since 4.3
+ */
+ public DigestSchemeFactory(final Charset charset) {
+ super();
+ this.charset = charset;
+ }
+
+ public DigestSchemeFactory() {
+ this(null);
+ }
+
public AuthScheme newInstance(final HttpParams params) {
return new DigestScheme();
}
public AuthScheme create(final HttpContext context) {
- return new DigestScheme();
+ return new DigestScheme(this.charset);
}
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java b/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java
index 075c0a136..6fac848f5 100644
--- a/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java
+++ b/httpclient/src/main/java/org/apache/http/impl/auth/GGSSchemeBase.java
@@ -36,8 +36,9 @@ import org.apache.http.auth.ContextAwareAuthScheme;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.InvalidCredentialsException;
import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.message.BasicHeader;
-import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.CharArrayBuffer;
import org.ietf.jgss.GSSContext;
@@ -131,16 +132,18 @@ public abstract class GGSSchemeBase extends AuthSchemeBase {
throw new AuthenticationException(getSchemeName() + " authentication has failed");
case CHALLENGE_RECEIVED:
try {
- String key = null;
- if (isProxy()) {
- key = ExecutionContext.HTTP_PROXY_HOST;
- } else {
- key = ExecutionContext.HTTP_TARGET_HOST;
+ HttpRoute route = (HttpRoute) context.getAttribute(ClientContext.ROUTE);
+ if (route == null) {
+ throw new AuthenticationException("Connection route is not available");
}
- HttpHost host = (HttpHost) context.getAttribute(key);
- if (host == null) {
- throw new AuthenticationException("Authentication host is not set " +
- "in the execution context");
+ HttpHost host;
+ if (isProxy()) {
+ host = route.getProxyHost();
+ if (host == null) {
+ host = route.getTargetHost();
+ }
+ } else {
+ host = route.getTargetHost();
}
String authServer;
if (!this.stripPort && host.getPort() > 0) {
diff --git a/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java b/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
index 6fc47e67c..ddca806e1 100644
--- a/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
+++ b/httpclient/src/main/java/org/apache/http/impl/auth/RFC2617Scheme.java
@@ -26,15 +26,19 @@
package org.apache.http.impl.auth;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.Consts;
import org.apache.http.HeaderElement;
+import org.apache.http.HttpRequest;
import org.apache.http.auth.ChallengeState;
import org.apache.http.auth.MalformedChallengeException;
+import org.apache.http.auth.params.AuthPNames;
import org.apache.http.message.BasicHeaderValueParser;
import org.apache.http.message.HeaderValueParser;
import org.apache.http.message.ParserCursor;
@@ -47,27 +51,55 @@ import org.apache.http.util.CharArrayBuffer;
*
* @since 4.0
*/
+@SuppressWarnings("deprecation")
@NotThreadSafe // AuthSchemeBase, params
public abstract class RFC2617Scheme extends AuthSchemeBase {
- /**
- * Authentication parameter map.
- */
private final Map params;
+ private final Charset credentialsCharset;
/**
* Creates an instance of RFC2617Scheme with the given challenge
* state.
*
* @since 4.2
+ *
+ * @deprecated (4.3) do not use.
*/
+ @Deprecated
public RFC2617Scheme(final ChallengeState challengeState) {
super(challengeState);
this.params = new HashMap();
+ this.credentialsCharset = Consts.ASCII;
+ }
+
+ /**
+ * @since 4.3
+ */
+ public RFC2617Scheme(final Charset credentialsCharset) {
+ super();
+ this.params = new HashMap();
+ this.credentialsCharset = credentialsCharset != null ? credentialsCharset : Consts.ASCII;
}
public RFC2617Scheme() {
- this(null);
+ this(Consts.ASCII);
+ }
+
+
+ /**
+ * @since 4.3
+ */
+ public Charset getCredentialsCharset() {
+ return credentialsCharset;
+ }
+
+ String getCredentialsCharset(final HttpRequest request) {
+ String charset = (String) request.getParams().getParameter(AuthPNames.CREDENTIAL_CHARSET);
+ if (charset == null) {
+ charset = getCredentialsCharset().name();
+ }
+ return charset;
}
@Override
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/AuthenticationStrategyImpl.java b/httpclient/src/main/java/org/apache/http/impl/client/AuthenticationStrategyImpl.java
index 44cc4d143..67e25423a 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/AuthenticationStrategyImpl.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/AuthenticationStrategyImpl.java
@@ -28,6 +28,7 @@
package org.apache.http.impl.client;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
@@ -52,7 +53,8 @@ import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.client.AuthCache;
import org.apache.http.client.AuthenticationStrategy;
import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.params.AuthPolicy;
+import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Lookup;
import org.apache.http.protocol.HTTP;
@@ -60,28 +62,26 @@ import org.apache.http.protocol.HttpContext;
import org.apache.http.util.CharArrayBuffer;
@Immutable
-class AuthenticationStrategyImpl implements AuthenticationStrategy {
+abstract class AuthenticationStrategyImpl implements AuthenticationStrategy {
private final Log log = LogFactory.getLog(getClass());
private static final List DEFAULT_SCHEME_PRIORITY =
Collections.unmodifiableList(Arrays.asList(new String[] {
- AuthPolicy.SPNEGO,
- AuthPolicy.KERBEROS,
- AuthPolicy.NTLM,
- AuthPolicy.DIGEST,
- AuthPolicy.BASIC
+ AuthSchemes.SPNEGO,
+ AuthSchemes.KERBEROS,
+ AuthSchemes.NTLM,
+ AuthSchemes.DIGEST,
+ AuthSchemes.BASIC
}));
private final int challengeCode;
private final String headerName;
- private final String prefParamName;
- AuthenticationStrategyImpl(int challengeCode, final String headerName, final String prefParamName) {
+ AuthenticationStrategyImpl(int challengeCode, final String headerName) {
super();
this.challengeCode = challengeCode;
this.headerName = headerName;
- this.prefParamName = prefParamName;
}
public boolean isAuthenticationRequested(
@@ -133,6 +133,8 @@ class AuthenticationStrategyImpl implements AuthenticationStrategy {
return map;
}
+ abstract Collection getPreferredAuthSchemes(RequestConfig config);
+
public Queue select(
final Map challenges,
final HttpHost authhost,
@@ -163,9 +165,8 @@ class AuthenticationStrategyImpl implements AuthenticationStrategy {
this.log.debug("Credentials provider not set in the context");
return options;
}
-
- @SuppressWarnings("unchecked")
- List authPrefs = (List) response.getParams().getParameter(this.prefParamName);
+ RequestConfig config = clientContext.getRequestConfig();
+ Collection authPrefs = getPreferredAuthSchemes(config);
if (authPrefs == null) {
authPrefs = DEFAULT_SCHEME_PRIORITY;
}
@@ -240,8 +241,8 @@ class AuthenticationStrategyImpl implements AuthenticationStrategy {
return false;
}
String schemeName = authScheme.getSchemeName();
- return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
- schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
+ return schemeName.equalsIgnoreCase(AuthSchemes.BASIC) ||
+ schemeName.equalsIgnoreCase(AuthSchemes.DIGEST);
}
public void authFailed(
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java
index c630a71aa..e45bedbf3 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java
@@ -41,13 +41,13 @@ import org.apache.http.ProtocolException;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.CircularRedirectException;
import org.apache.http.client.RedirectStrategy;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
-import org.apache.http.client.params.ClientPNames;
+import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIUtils;
-import org.apache.http.params.HttpParams;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
@@ -126,6 +126,9 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
+
+ HttpClientContext clientContext = HttpClientContext.adapt(context);
+
//get the location header to find out where to redirect to
Header locationHeader = response.getFirstHeader("location");
if (locationHeader == null) {
@@ -139,16 +142,17 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
this.log.debug("Redirect requested to location '" + location + "'");
}
+ RequestConfig config = clientContext.getRequestConfig();
+
URI uri = createLocationURI(location);
- HttpParams params = request.getParams();
// rfc2616 demands the location value be a complete URI
// Location = "Location" ":" absoluteURI
try {
// Drop fragment
uri = URIUtils.rewriteURI(uri);
if (!uri.isAbsolute()) {
- if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) {
+ if (!config.isRelativeRedirectsAllowed()) {
throw new ProtocolException("Relative redirect location '"
+ uri + "' not allowed");
}
@@ -172,7 +176,7 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
redirectLocations = new RedirectLocations();
context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
}
- if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {
+ if (!config.isCircularRedirectsAllowed()) {
if (redirectLocations.contains(uri)) {
throw new CircularRedirectException("Circular redirect to '" + uri + "'");
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/ProxyAuthenticationStrategy.java b/httpclient/src/main/java/org/apache/http/impl/client/ProxyAuthenticationStrategy.java
index e72934c9f..332970373 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/ProxyAuthenticationStrategy.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/ProxyAuthenticationStrategy.java
@@ -27,11 +27,13 @@
package org.apache.http.impl.client;
+import java.util.Collection;
+
import org.apache.http.HttpStatus;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AUTH;
-import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.AuthenticationStrategy;
+import org.apache.http.client.config.RequestConfig;
/**
* Default {@link AuthenticationStrategy} implementation for proxy host authentication.
@@ -44,7 +46,12 @@ public class ProxyAuthenticationStrategy extends AuthenticationStrategyImpl {
public static final ProxyAuthenticationStrategy INSTANCE = new ProxyAuthenticationStrategy();
public ProxyAuthenticationStrategy() {
- super(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, AUTH.PROXY_AUTH, AuthPNames.PROXY_AUTH_PREF);
+ super(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, AUTH.PROXY_AUTH);
+ }
+
+ @Override
+ Collection getPreferredAuthSchemes(final RequestConfig config) {
+ return config.getProxyPreferredAuthSchemes();
}
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/TargetAuthenticationStrategy.java b/httpclient/src/main/java/org/apache/http/impl/client/TargetAuthenticationStrategy.java
index b311f2097..86542ff10 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/TargetAuthenticationStrategy.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/TargetAuthenticationStrategy.java
@@ -27,11 +27,13 @@
package org.apache.http.impl.client;
+import java.util.Collection;
+
import org.apache.http.HttpStatus;
import org.apache.http.annotation.Immutable;
import org.apache.http.auth.AUTH;
-import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.AuthenticationStrategy;
+import org.apache.http.client.config.RequestConfig;
/**
* Default {@link AuthenticationStrategy} implementation for proxy host authentication.
@@ -44,7 +46,12 @@ public class TargetAuthenticationStrategy extends AuthenticationStrategyImpl {
public static final TargetAuthenticationStrategy INSTANCE = new TargetAuthenticationStrategy();
public TargetAuthenticationStrategy() {
- super(HttpStatus.SC_UNAUTHORIZED, AUTH.WWW_AUTH, AuthPNames.TARGET_AUTH_PREF);
+ super(HttpStatus.SC_UNAUTHORIZED, AUTH.WWW_AUTH);
+ }
+
+ @Override
+ Collection getPreferredAuthSchemes(final RequestConfig config) {
+ return config.getTargetPreferredAuthSchemes();
}
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java
index 31521d2cb..a97a3e7aa 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/BackoffStrategyExec.java
@@ -36,8 +36,8 @@ import org.apache.http.client.BackoffManager;
import org.apache.http.client.ConnectionBackoffStrategy;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
+import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.protocol.HttpContext;
/**
* @since 4.3
@@ -71,7 +71,7 @@ class BackoffStrategyExec implements ClientExecChain {
public CloseableHttpResponse execute(
final HttpRoute route,
final HttpRequestWrapper request,
- final HttpContext context,
+ final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
if (route == null) {
throw new IllegalArgumentException("HTTP route may not be null");
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/ClientExecChain.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/ClientExecChain.java
index 91556d925..a6af3c5e9 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/ClientExecChain.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/ClientExecChain.java
@@ -32,8 +32,8 @@ import java.io.IOException;
import org.apache.http.HttpException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
+import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.protocol.HttpContext;
/**
* This interface represents an element in the HTTP request execution chain. Each element can
@@ -52,7 +52,7 @@ interface ClientExecChain {
CloseableHttpResponse execute(
HttpRoute route,
HttpRequestWrapper request,
- HttpContext context,
+ HttpClientContext clientContext,
HttpExecutionAware execAware) throws IOException, HttpException;
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java
index 6ba4b4338..d22337c7d 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpClientBuilder.java
@@ -28,11 +28,13 @@
package org.apache.http.impl.client.builder;
import java.net.ProxySelector;
+import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.Header;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.annotation.NotThreadSafe;
@@ -47,13 +49,15 @@ import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.ServiceUnavailableRetryStrategy;
import org.apache.http.client.UserTokenHandler;
-import org.apache.http.client.params.AuthPolicy;
-import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.protocol.RequestAcceptEncoding;
import org.apache.http.client.protocol.RequestAddCookies;
import org.apache.http.client.protocol.RequestAuthCache;
import org.apache.http.client.protocol.RequestClientConnControl;
import org.apache.http.client.protocol.RequestDefaultHeaders;
+import org.apache.http.client.protocol.RequestExpectContinue;
import org.apache.http.client.protocol.ResponseContentEncoding;
import org.apache.http.client.protocol.ResponseProcessCookies;
import org.apache.http.config.Lookup;
@@ -98,7 +102,6 @@ import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpProcessorBuilder;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.RequestContent;
-import org.apache.http.protocol.RequestExpectContinue;
import org.apache.http.protocol.RequestTargetHost;
import org.apache.http.protocol.RequestUserAgent;
import org.apache.http.util.VersionInfo;
@@ -125,6 +128,7 @@ import org.apache.http.util.VersionInfo;
* http.nonProxyHosts
* http.keepAlive
* http.maxConnections
+ * http.user
*
*
*
@@ -161,6 +165,9 @@ public class HttpClientBuilder {
private Map cookieSpecs;
private CookieStore cookieStore;
private CredentialsProvider credentialsProvider;
+ private String userAgent;
+ private Collection extends Header> defaultHeaders;
+ private RequestConfig defaultConfig;
private boolean systemProperties;
private boolean redirectHandlingDisabled;
@@ -365,6 +372,21 @@ public class HttpClientBuilder {
return this;
}
+ public final HttpClientBuilder setUserAgent(final String userAgent) {
+ this.userAgent = userAgent;
+ return this;
+ }
+
+ public final HttpClientBuilder setDefaultHeaders(final Collection extends Header> defaultHeaders) {
+ this.defaultHeaders = defaultHeaders;
+ return this;
+ }
+
+ public final HttpClientBuilder setDefaultConfig(final RequestConfig defaultConfig) {
+ this.defaultConfig = defaultConfig;
+ return this;
+ }
+
public final HttpClientBuilder disableRedirectHandling() {
redirectHandlingDisabled = true;
return this;
@@ -489,10 +511,17 @@ public class HttpClientBuilder {
HttpProcessor httpprocessor = this.httpprocessor;
if (httpprocessor == null) {
- VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client",
- HttpClientBuilder.class.getClassLoader());
- String release = vi != null ? vi.getRelease() : VersionInfo.UNAVAILABLE;
- String defaultAgent = "Apache-HttpClient/" + release + " (java 1.5)";
+ String userAgent = this.userAgent;
+ if (userAgent == null) {
+ if (systemProperties) {
+ userAgent = System.getProperty("http.agent");
+ } else {
+ VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client",
+ HttpClientBuilder.class.getClassLoader());
+ String release = vi != null ? vi.getRelease() : VersionInfo.UNAVAILABLE;
+ userAgent = "Apache-HttpClient/" + release + " (java 1.5)";
+ }
+ }
HttpProcessorBuilder b = HttpProcessorBuilder.create();
if (requestFirst != null) {
@@ -506,11 +535,11 @@ public class HttpClientBuilder {
}
}
b.addAll(
- new RequestDefaultHeaders(),
+ new RequestDefaultHeaders(defaultHeaders),
new RequestContent(),
new RequestTargetHost(),
new RequestClientConnControl(),
- new RequestUserAgent(defaultAgent),
+ new RequestUserAgent(userAgent),
new RequestExpectContinue());
if (!cookieManagementDisabled) {
b.add(new RequestAddCookies());
@@ -585,11 +614,11 @@ public class HttpClientBuilder {
Lookup authSchemeRegistry = this.authSchemeRegistry;
if (authSchemeRegistry == null) {
RegistryBuilder b = RegistryBuilder.create();
- b.register(AuthPolicy.BASIC, new BasicSchemeFactory())
- .register(AuthPolicy.DIGEST, new DigestSchemeFactory())
- .register(AuthPolicy.NTLM, new NTLMSchemeFactory())
- .register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory())
- .register(AuthPolicy.KERBEROS, new KerberosSchemeFactory())
+ b.register(AuthSchemes.BASIC, new BasicSchemeFactory())
+ .register(AuthSchemes.DIGEST, new DigestSchemeFactory())
+ .register(AuthSchemes.NTLM, new NTLMSchemeFactory())
+ .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
+ .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
.build();
if (authShemes != null) {
for (Map.Entry entry: authShemes.entrySet()) {
@@ -601,12 +630,12 @@ public class HttpClientBuilder {
Lookup cookieSpecRegistry = this.cookieSpecRegistry;
if (cookieSpecRegistry == null) {
RegistryBuilder b = RegistryBuilder.create();
- b.register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory())
- .register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
- .register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory())
- .register(CookiePolicy.RFC_2109, new RFC2109SpecFactory())
- .register(CookiePolicy.RFC_2965, new RFC2965SpecFactory())
- .register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory());
+ b.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
+ .register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
+ .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
+ .register(CookieSpecs.RFC_2109, new RFC2109SpecFactory())
+ .register(CookieSpecs.RFC_2965, new RFC2965SpecFactory())
+ .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory());
if (cookieSpecs != null) {
for (Map.Entry entry: cookieSpecs.entrySet()) {
b.register(entry.getKey(), entry.getValue());
@@ -632,7 +661,8 @@ public class HttpClientBuilder {
cookieSpecRegistry,
authSchemeRegistry,
defaultCookieStore,
- defaultCredentialsProvider);
+ defaultCredentialsProvider,
+ defaultConfig != null ? defaultConfig : RequestConfig.DEFAULT);
}
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java
index 3458b019d..de98fcde6 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/HttpRequestWrapper.java
@@ -66,7 +66,6 @@ class HttpRequestWrapper extends AbstractHttpMessage implements HttpRequest {
} else {
this.uri = null;
}
- setParams(request.getParams());
setHeaders(request.getAllHeaders());
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java
index 690d04304..28a3478ff 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/InternalHttpClient.java
@@ -39,9 +39,12 @@ import org.apache.http.auth.AuthState;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.Configurable;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.params.ClientPNames;
+import org.apache.http.client.params.HttpParamConfig;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Lookup;
@@ -54,9 +57,8 @@ import org.apache.http.conn.routing.HttpRoutePlanner;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.params.DefaultedHttpParams;
+import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
-import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
@@ -64,6 +66,7 @@ import org.apache.http.protocol.HttpContext;
* @since 4.3
*/
@ThreadSafe
+@SuppressWarnings("deprecation")
class InternalHttpClient extends CloseableHttpClient {
private final ClientExecChain execChain;
@@ -73,6 +76,7 @@ class InternalHttpClient extends CloseableHttpClient {
private final Lookup authSchemeRegistry;
private final CookieStore cookieStore;
private final CredentialsProvider credentialsProvider;
+ private final RequestConfig defaultConfig;
private final HttpParams params;
public InternalHttpClient(
@@ -82,7 +86,8 @@ class InternalHttpClient extends CloseableHttpClient {
final Lookup cookieSpecRegistry,
final Lookup authSchemeRegistry,
final CookieStore cookieStore,
- final CredentialsProvider credentialsProvider) {
+ final CredentialsProvider credentialsProvider,
+ final RequestConfig defaultConfig) {
super();
if (execChain == null) {
throw new IllegalArgumentException("HTTP client exec chain may not be null");
@@ -100,7 +105,8 @@ class InternalHttpClient extends CloseableHttpClient {
this.authSchemeRegistry = authSchemeRegistry;
this.cookieStore = cookieStore;
this.credentialsProvider = credentialsProvider;
- this.params = new SyncBasicHttpParams();
+ this.defaultConfig = defaultConfig != null ? defaultConfig : RequestConfig.DEFAULT;
+ this.params = new BasicHttpParams();
}
private HttpRoute determineRoute(
@@ -117,7 +123,7 @@ class InternalHttpClient extends CloseableHttpClient {
return this.routePlanner.determineRoute(host, request, context);
}
- private HttpContext setupContext(final HttpContext localContext) {
+ private HttpClientContext setupContext(final HttpContext localContext) {
HttpClientContext context = HttpClientContext.adapt(
localContext != null ? localContext : new BasicHttpContext());
if (context.getAttribute(ClientContext.TARGET_AUTH_STATE) == null) {
@@ -154,14 +160,23 @@ class InternalHttpClient extends CloseableHttpClient {
execListner = (HttpExecutionAware) request;
}
try {
- HttpParams params = new DefaultedHttpParams(request.getParams(), getParams());
+ HttpParams params = request.getParams();
HttpHost virtualHost = (HttpHost) params.getParameter(ClientPNames.VIRTUAL_HOST);
HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
- wrapper.setParams(params);
wrapper.setVirtualHost(virtualHost);
- HttpContext localcontext = setupContext(context);
+ HttpClientContext localcontext = setupContext(context);
HttpRoute route = determineRoute(target, wrapper, localcontext);
+ RequestConfig config = null;
+ if (request instanceof Configurable) {
+ config = ((Configurable) request).getConfig();
+ } else {
+ config = HttpParamConfig.getRequestConfig(params);
+ }
+ if (config == null) {
+ config = this.defaultConfig;
+ }
+ localcontext.setRequestConfig(config);
return this.execChain.execute(route, wrapper, localcontext, execListner);
} catch (HttpException httpException) {
throw new ClientProtocolException(httpException);
@@ -173,10 +188,9 @@ class InternalHttpClient extends CloseableHttpClient {
}
public void close() {
- connManager.shutdown();
+ this.connManager.shutdown();
}
- @SuppressWarnings("deprecation")
public ClientConnectionManager getConnectionManager() {
return new ClientConnectionManager() {
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java
index 6c913e1d4..179168c53 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/MainClientExec.java
@@ -41,7 +41,6 @@ import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
-import org.apache.http.ProtocolVersion;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.auth.AUTH;
import org.apache.http.auth.AuthProtocolState;
@@ -49,9 +48,9 @@ import org.apache.http.auth.AuthState;
import org.apache.http.client.AuthenticationStrategy;
import org.apache.http.client.NonRepeatableRequestException;
import org.apache.http.client.UserTokenHandler;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
-import org.apache.http.client.params.HttpClientParams;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.protocol.RequestClientConnControl;
@@ -68,11 +67,7 @@ import org.apache.http.impl.client.RequestAbortedException;
import org.apache.http.impl.client.TunnelRefusedException;
import org.apache.http.impl.conn.ConnectionShutdownException;
import org.apache.http.message.BasicHttpRequest;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.ExecutionContext;
-import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.ImmutableHttpProcessor;
@@ -80,30 +75,6 @@ import org.apache.http.protocol.RequestUserAgent;
import org.apache.http.util.EntityUtils;
/**
- *
- * The following parameters can be used to customize the behavior of this
- * class:
- *
- * - {@link org.apache.http.params.CoreProtocolPNames#PROTOCOL_VERSION}
- * - {@link org.apache.http.params.CoreProtocolPNames#STRICT_TRANSFER_ENCODING}
- * - {@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}
- * - {@link org.apache.http.params.CoreProtocolPNames#USE_EXPECT_CONTINUE}
- * - {@link org.apache.http.params.CoreProtocolPNames#WAIT_FOR_CONTINUE}
- * - {@link org.apache.http.params.CoreProtocolPNames#USER_AGENT}
- * - {@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}
- * - {@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}
- * - {@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}
- * - {@link org.apache.http.params.CoreConnectionPNames#SO_TIMEOUT}
- * - {@link org.apache.http.params.CoreConnectionPNames#SO_LINGER}
- * - {@link org.apache.http.params.CoreConnectionPNames#SO_REUSEADDR}
- * - {@link org.apache.http.params.CoreConnectionPNames#TCP_NODELAY}
- * - {@link org.apache.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}
- * - {@link org.apache.http.params.CoreConnectionPNames#STALE_CONNECTION_CHECK}
- * - {@link org.apache.http.auth.params.AuthPNames#CREDENTIAL_CHARSET}
- * - {@link org.apache.http.client.params.ClientPNames#HANDLE_AUTHENTICATION}
- * - {@link org.apache.http.client.params.ClientPNames#CONN_MANAGER_TIMEOUT}
- *
- *
* @since 4.3
*/
@ThreadSafe
@@ -170,7 +141,7 @@ class MainClientExec implements ClientExecChain {
public CloseableHttpResponse execute(
final HttpRoute route,
final HttpRequestWrapper request,
- final HttpContext context,
+ final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
if (route == null) {
throw new IllegalArgumentException("HTTP route may not be null");
@@ -182,22 +153,18 @@ class MainClientExec implements ClientExecChain {
throw new IllegalArgumentException("HTTP context may not be null");
}
- HttpClientContext clientContext = HttpClientContext.adapt(context);
-
- AuthState targetAuthState = clientContext.getTargetAuthState();
+ AuthState targetAuthState = context.getTargetAuthState();
if (targetAuthState == null) {
targetAuthState = new AuthState();
context.setAttribute(ClientContext.TARGET_AUTH_STATE, targetAuthState);
}
- AuthState proxyAuthState = clientContext.getProxyAuthState();
+ AuthState proxyAuthState = context.getProxyAuthState();
if (proxyAuthState == null) {
proxyAuthState = new AuthState();
context.setAttribute(ClientContext.PROXY_AUTH_STATE, proxyAuthState);
}
- HttpParams params = request.getParams();
-
- Object userToken = clientContext.getUserToken();
+ Object userToken = context.getUserToken();
final ConnectionRequest connRequest = connManager.requestConnection(route, userToken);
if (execAware != null) {
@@ -209,17 +176,19 @@ class MainClientExec implements ClientExecChain {
}
}
+ RequestConfig config = context.getRequestConfig();
+
HttpClientConnection managedConn;
try {
- long timeout = HttpClientParams.getConnectionManagerTimeout(params);
- managedConn = connRequest.get(timeout, TimeUnit.MILLISECONDS);
+ int timeout = config.getConnectionRequestTimeout();
+ managedConn = connRequest.get(timeout > 0 ? timeout : 0, TimeUnit.MILLISECONDS);
} catch(InterruptedException interrupted) {
throw new RequestAbortedException("Request aborted", interrupted);
}
context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn);
- if (HttpConnectionParams.isStaleCheckingEnabled(params)) {
+ if (config.isStaleConnectionCheckEnabled()) {
// validate connection
if (managedConn.isOpen()) {
this.log.debug("Stale connection check");
@@ -266,7 +235,10 @@ class MainClientExec implements ClientExecChain {
break;
}
} else {
- managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
+ int timeout = config.getSocketTimeout();
+ if (timeout >= 0) {
+ managedConn.setSocketTimeout(timeout);
+ }
}
if (execAware != null && execAware.isAborted()) {
@@ -291,7 +263,6 @@ class MainClientExec implements ClientExecChain {
}
response = requestExecutor.execute(request, managedConn, context);
- response.setParams(params);
// The connection is in or can be brought to a re-usable state.
if (reuseStrategy.keepAlive(response, context)) {
@@ -385,8 +356,9 @@ class MainClientExec implements ClientExecChain {
final HttpClientConnection managedConn,
final HttpRoute route,
final HttpRequest request,
- final HttpContext context) throws HttpException, IOException {
- HttpParams params = request.getParams();
+ final HttpClientContext context) throws HttpException, IOException {
+ RequestConfig config = context.getRequestConfig();
+ int timeout = config.getConnectTimeout();
RouteTracker tracker = new RouteTracker(route);
int step;
do {
@@ -397,17 +369,24 @@ class MainClientExec implements ClientExecChain {
case HttpRouteDirector.CONNECT_TARGET:
this.connManager.connect(
- managedConn, route.getTargetHost(), route.getLocalAddress(), context);
+ managedConn,
+ route.getTargetHost(), route.getLocalAddress(),
+ timeout > 0 ? timeout : 0,
+ context);
tracker.connectTarget(route.isSecure());
break;
case HttpRouteDirector.CONNECT_PROXY:
this.connManager.connect(
- managedConn, route.getProxyHost(), route.getLocalAddress(), context);
+ managedConn,
+ route.getProxyHost(), route.getLocalAddress(),
+ timeout > 0 ? timeout : 0,
+ context);
HttpHost proxy = route.getProxyHost();
tracker.connectProxy(proxy, false);
break;
case HttpRouteDirector.TUNNEL_TARGET: {
- boolean secure = createTunnelToTarget(proxyAuthState, managedConn, route, request, context);
+ boolean secure = createTunnelToTarget(
+ proxyAuthState, managedConn, route, request, context);
this.log.debug("Tunnel to target created.");
tracker.tunnelTarget(secure);
} break;
@@ -454,24 +433,27 @@ class MainClientExec implements ClientExecChain {
final HttpClientConnection managedConn,
final HttpRoute route,
final HttpRequest request,
- final HttpContext context) throws HttpException, IOException {
+ final HttpClientContext context) throws HttpException, IOException {
+
+ RequestConfig config = context.getRequestConfig();
+ int timeout = config.getConnectTimeout();
- HttpParams params = request.getParams();
HttpHost target = route.getTargetHost();
HttpHost proxy = route.getProxyHost();
HttpResponse response = null;
String authority = target.toHostString();
- ProtocolVersion ver = HttpProtocolParams.getVersion(params);
- HttpRequest connect = new BasicHttpRequest("CONNECT", authority, ver);
- connect.setParams(params);
+ HttpRequest connect = new BasicHttpRequest("CONNECT", authority, request.getProtocolVersion());
this.requestExecutor.preProcess(connect, this.proxyHttpProcessor, context);
for (;;) {
if (!managedConn.isOpen()) {
this.connManager.connect(
- managedConn, route.getProxyHost(), route.getLocalAddress(), context);
+ managedConn,
+ route.getProxyHost(), route.getLocalAddress(),
+ timeout > 0 ? timeout : 0,
+ context);
}
connect.removeHeaders(AUTH.PROXY_AUTH_RESP);
@@ -485,7 +467,7 @@ class MainClientExec implements ClientExecChain {
response.getStatusLine());
}
- if (HttpClientParams.isAuthenticating(params)) {
+ if (config.isAuthenticationEnabled()) {
if (this.authenticator.isAuthenticationRequested(proxy, response,
this.proxyAuthStrategy, proxyAuthState, context)) {
if (this.authenticator.handleAuthChallenge(proxy, response,
@@ -538,7 +520,7 @@ class MainClientExec implements ClientExecChain {
private boolean createTunnelToProxy(
final HttpRoute route,
final int hop,
- final HttpContext context) throws HttpException, IOException {
+ final HttpClientContext context) throws HttpException, IOException {
// Have a look at createTunnelToTarget and replicate the parts
// you need in a custom derived class. If your proxies don't require
@@ -558,11 +540,10 @@ class MainClientExec implements ClientExecChain {
final HttpRoute route,
final HttpRequestWrapper request,
final HttpResponse response,
- final HttpContext context) throws HttpException, IOException {
-
- HttpParams params = request.getParams();
- if (HttpClientParams.isAuthenticating(params)) {
- HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
+ final HttpClientContext context) throws HttpException, IOException {
+ RequestConfig config = context.getRequestConfig();
+ if (config.isAuthenticationEnabled()) {
+ HttpHost target = context.getTargetHost();
if (target == null) {
target = route.getTargetHost();
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java
index de27eed70..40645999b 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/ProtocolExec.java
@@ -47,7 +47,6 @@ import org.apache.http.client.utils.URIUtils;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.protocol.ExecutionContext;
-import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
/**
@@ -107,7 +106,7 @@ class ProtocolExec implements ClientExecChain {
public CloseableHttpResponse execute(
final HttpRoute route,
final HttpRequestWrapper request,
- final HttpContext context,
+ final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
if (route == null) {
throw new IllegalArgumentException("HTTP route may not be null");
@@ -119,12 +118,10 @@ class ProtocolExec implements ClientExecChain {
throw new IllegalArgumentException("HTTP context may not be null");
}
- HttpClientContext clientContext = HttpClientContext.adapt(context);
-
HttpHost target = route.getTargetHost();
// Get user info from the URI
- AuthState targetAuthState = clientContext.getTargetAuthState();
+ AuthState targetAuthState = context.getTargetAuthState();
if (targetAuthState != null) {
String userinfo = request.getURI().getUserInfo();
if (userinfo != null) {
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java
index 261d864f2..706259fa2 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/RedirectExec.java
@@ -41,27 +41,16 @@ import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthState;
import org.apache.http.client.RedirectException;
import org.apache.http.client.RedirectStrategy;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.client.params.HttpClientParams;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
-import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
/**
- * The following parameters can be used to customize the behavior of this
- * class:
- *
- * - {@link org.apache.http.client.params.ClientPNames#HANDLE_REDIRECTS}
- * - {@link org.apache.http.client.params.ClientPNames#MAX_REDIRECTS}
- * - {@link org.apache.http.client.params.ClientPNames#ALLOW_CIRCULAR_REDIRECTS}
- *
- *
* @since 4.3
*/
@ThreadSafe
@@ -95,7 +84,7 @@ class RedirectExec implements ClientExecChain {
public CloseableHttpResponse execute(
final HttpRoute route,
final HttpRequestWrapper request,
- final HttpContext context,
+ final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
if (route == null) {
throw new IllegalArgumentException("HTTP route may not be null");
@@ -107,17 +96,15 @@ class RedirectExec implements ClientExecChain {
throw new IllegalArgumentException("HTTP context may not be null");
}
- HttpClientContext clientContext = HttpClientContext.adapt(context);
-
- HttpParams params = request.getParams();
- int maxRedirects = params.getIntParameter(ClientPNames.MAX_REDIRECTS, 100);
+ RequestConfig config = context.getRequestConfig();
+ int maxRedirects = config.getMaxRedirects() > 0 ? config.getMaxRedirects() : 50;
HttpRoute currentRoute = route;
HttpRequestWrapper currentRequest = request;
for (int redirectCount = 0;;) {
CloseableHttpResponse response = requestExecutor.execute(
currentRoute, currentRequest, context, execAware);
try {
- if (HttpClientParams.isRedirecting(params) &&
+ if (config.isRedirectsEnabled() &&
this.redirectStrategy.isRedirected(currentRequest, response, context)) {
if (redirectCount >= maxRedirects) {
@@ -129,7 +116,6 @@ class RedirectExec implements ClientExecChain {
HttpRequest original = currentRequest.getOriginal();
currentRequest = HttpRequestWrapper.wrap(redirect);
currentRequest.setHeaders(original.getAllHeaders());
- currentRequest.setParams(params);
URI uri = currentRequest.getURI();
HttpHost newTarget = URIUtils.extractHost(uri);
@@ -140,12 +126,12 @@ class RedirectExec implements ClientExecChain {
// Reset virtual host and auth states if redirecting to another host
if (!currentRoute.getTargetHost().equals(newTarget)) {
- AuthState targetAuthState = clientContext.getTargetAuthState();
+ AuthState targetAuthState = context.getTargetAuthState();
if (targetAuthState != null) {
this.log.debug("Resetting target auth state");
targetAuthState.reset();
}
- AuthState proxyAuthState = clientContext.getProxyAuthState();
+ AuthState proxyAuthState = context.getProxyAuthState();
if (proxyAuthState != null) {
AuthScheme authScheme = proxyAuthState.getAuthScheme();
if (authScheme != null && authScheme.isConnectionBased()) {
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java
index 30ab88ea0..810fc045b 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/RetryExec.java
@@ -40,8 +40,8 @@ import org.apache.http.client.NonRepeatableRequestException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.protocol.HttpContext;
/**
* @since 4.3
@@ -70,7 +70,7 @@ class RetryExec implements ClientExecChain {
public CloseableHttpResponse execute(
final HttpRoute route,
final HttpRequestWrapper request,
- final HttpContext context,
+ final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
if (route == null) {
throw new IllegalArgumentException("HTTP route may not be null");
diff --git a/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java b/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java
index 2f7d4ca56..c01b538dc 100644
--- a/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java
+++ b/httpclient/src/main/java/org/apache/http/impl/client/builder/ServiceUnavailableRetryExec.java
@@ -37,8 +37,8 @@ import org.apache.http.annotation.ThreadSafe;
import org.apache.http.client.ServiceUnavailableRetryStrategy;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpExecutionAware;
+import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.protocol.HttpContext;
/**
* {@link ClientExecChain} implementation that can automatically retry the request in case of
@@ -72,7 +72,7 @@ class ServiceUnavailableRetryExec implements ClientExecChain {
public CloseableHttpResponse execute(
final HttpRoute route,
final HttpRequestWrapper request,
- final HttpContext context,
+ final HttpClientContext context,
final HttpExecutionAware execAware) throws IOException, HttpException {
for (int c = 1;; c++) {
CloseableHttpResponse response = this.requestExecutor.execute(
diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java b/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
index 3579705df..79a2250aa 100644
--- a/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
+++ b/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
@@ -308,6 +308,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
final HttpClientConnection conn,
final HttpHost host,
final InetAddress local,
+ final int connectTimeout,
final HttpContext context) throws IOException {
if (conn == null) {
throw new IllegalArgumentException("Connection may not be null");
@@ -320,7 +321,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
}
InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
this.connectionOperator.connect(this.conn, host, localAddress,
- this.connConfig.getConnectTimeout(), this.socketConfig, context);
+ connectTimeout, this.socketConfig, context);
}
public void upgrade(
diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java
index a6480ef7a..0a78da157 100644
--- a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java
+++ b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultRoutePlanner.java
@@ -33,8 +33,9 @@ import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.annotation.Immutable;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.SchemePortResolver;
-import org.apache.http.conn.params.ConnRouteParams;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRoutePlanner;
import org.apache.http.protocol.HttpContext;
@@ -44,14 +45,6 @@ import org.apache.http.protocol.HttpContext;
* is based on {@link org.apache.http.conn.params.ConnRoutePNames parameters}.
* It will not make use of any Java system properties, nor of system or
* browser proxy settings.
- *
- * The following parameters can be used to customize the behavior of this
- * class:
- *
- * - {@link org.apache.http.conn.params.ConnRoutePNames#DEFAULT_PROXY}
- * - {@link org.apache.http.conn.params.ConnRoutePNames#LOCAL_ADDRESS}
- * - {@link org.apache.http.conn.params.ConnRoutePNames#FORCED_ROUTE}
- *
*
* @since 4.3
*/
@@ -76,15 +69,13 @@ public class DefaultRoutePlanner implements HttpRoutePlanner {
if (request == null) {
throw new IllegalArgumentException("Request may not be null");
}
- // If we have a forced route, we can do without a target.
- HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
- if (route != null) {
- return route;
- }
- // If we get here, there is no forced route.
- // So we need a target to compute a route.
- InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
+ HttpClientContext clientContext = HttpClientContext.adapt(context);
+ RequestConfig config = clientContext.getRequestConfig();
+ InetAddress local = config.getLocalAddress();
HttpHost proxy = determineProxy(host, request, context);
+ if (proxy == null) {
+ proxy = config.getDefaultProxy();
+ }
HttpHost target;
if (host.getPort() <= 0) {
@@ -97,18 +88,17 @@ public class DefaultRoutePlanner implements HttpRoutePlanner {
}
boolean secure = target.getSchemeName().equalsIgnoreCase("https");
if (proxy == null) {
- route = new HttpRoute(target, local, secure);
+ return new HttpRoute(target, local, secure);
} else {
- route = new HttpRoute(target, local, proxy, secure);
+ return new HttpRoute(target, local, proxy, secure);
}
- return route;
}
protected HttpHost determineProxy(
final HttpHost target,
final HttpRequest request,
final HttpContext context) throws HttpException {
- return ConnRouteParams.getDefaultProxy(request.getParams());
+ return null;
}
}
diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java b/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java
index 575efda0f..ec4a8b597 100644
--- a/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java
+++ b/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionManagerBase.java
@@ -193,6 +193,7 @@ abstract class HttpClientConnectionManagerBase implements HttpClientConnectionMa
final HttpClientConnection managedConn,
final HttpHost host,
final InetAddress local,
+ final int connectTimeout,
final HttpContext context) throws IOException {
if (managedConn == null) {
throw new IllegalArgumentException("Connection may not be null");
@@ -213,7 +214,7 @@ abstract class HttpClientConnectionManagerBase implements HttpClientConnectionMa
InetSocketAddress localAddress = local != null ? new InetSocketAddress(local, 0) : null;
this.connectionOperator.connect(conn, host, localAddress,
- connConfig.getConnectTimeout(), socketConfig, context);
+ connectTimeout, socketConfig, context);
}
public void upgrade(
diff --git a/httpclient/src/test/java/org/apache/http/client/methods/TestHttpRequestBase.java b/httpclient/src/test/java/org/apache/http/client/methods/TestHttpRequestBase.java
index 619654eaf..fc5c8fa59 100644
--- a/httpclient/src/test/java/org/apache/http/client/methods/TestHttpRequestBase.java
+++ b/httpclient/src/test/java/org/apache/http/client/methods/TestHttpRequestBase.java
@@ -33,7 +33,6 @@ import org.apache.http.Header;
import org.apache.http.HttpVersion;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
-import org.apache.http.params.HttpProtocolParams;
import org.apache.http.util.LangUtils;
import org.junit.Assert;
import org.junit.Test;
@@ -43,11 +42,9 @@ public class TestHttpRequestBase {
@Test
public void testBasicProperties() throws Exception {
HttpGet httpget = new HttpGet("http://host/path");
- httpget.getParams().setParameter(
- HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
Assert.assertEquals("GET", httpget.getRequestLine().getMethod());
Assert.assertEquals("http://host/path", httpget.getRequestLine().getUri());
- Assert.assertEquals(HttpVersion.HTTP_1_0, httpget.getRequestLine().getProtocolVersion());
+ Assert.assertEquals(HttpVersion.HTTP_1_1, httpget.getRequestLine().getProtocolVersion());
}
@Test
@@ -62,8 +59,6 @@ public class TestHttpRequestBase {
httpget.addHeader("h1", "this header");
httpget.addHeader("h2", "that header");
httpget.addHeader("h3", "all sorts of headers");
- httpget.getParams().setParameter("p1", Integer.valueOf(1));
- httpget.getParams().setParameter("p2", "whatever");
HttpGet clone = (HttpGet) httpget.clone();
Assert.assertEquals(httpget.getMethod(), clone.getMethod());
@@ -73,11 +68,6 @@ public class TestHttpRequestBase {
Header[] headers2 = clone.getAllHeaders();
Assert.assertTrue(LangUtils.equals(headers1, headers2));
- Assert.assertTrue(httpget.getParams() != clone.getParams());
-
- Assert.assertEquals(Integer.valueOf(1), clone.getParams().getParameter("p1"));
- Assert.assertEquals("whatever", clone.getParams().getParameter("p2"));
- Assert.assertEquals(null, clone.getParams().getParameter("p3"));
}
@Test
@@ -86,8 +76,6 @@ public class TestHttpRequestBase {
httppost.addHeader("h1", "this header");
httppost.addHeader("h2", "that header");
httppost.addHeader("h3", "all sorts of headers");
- httppost.getParams().setParameter("p1", Integer.valueOf(1));
- httppost.getParams().setParameter("p2", "whatever");
HttpPost clone = (HttpPost) httppost.clone();
Assert.assertEquals(httppost.getMethod(), clone.getMethod());
@@ -97,11 +85,6 @@ public class TestHttpRequestBase {
Header[] headers2 = clone.getAllHeaders();
Assert.assertTrue(LangUtils.equals(headers1, headers2));
- Assert.assertTrue(httppost.getParams() != clone.getParams());
-
- Assert.assertEquals(Integer.valueOf(1), clone.getParams().getParameter("p1"));
- Assert.assertEquals("whatever", clone.getParams().getParameter("p2"));
- Assert.assertEquals(null, clone.getParams().getParameter("p3"));
Assert.assertNull(clone.getEntity());
diff --git a/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java b/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
index 256366930..a69fd947d 100644
--- a/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
+++ b/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
@@ -33,11 +33,10 @@ import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpVersion;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
import org.junit.Assert;
import org.junit.Test;
@@ -89,14 +88,14 @@ public class TestRequestBuilder {
@Test
public void testCopy() throws Exception {
HttpEntity entity = new StringEntity("stuff");
- HttpParams params = new BasicHttpParams();
+ RequestConfig config = RequestConfig.custom().build();
HttpUriRequest request = RequestBuilder.createPut()
.setUri(URI.create("/stuff"))
.setVersion(HttpVersion.HTTP_1_0)
.addHeader("header1", "stuff")
.setHeader("header2", "more stuff")
.setEntity(entity)
- .setParams(params)
+ .setConfig(config)
.build();
Assert.assertNotNull(request);
Assert.assertEquals("PUT", request.getMethod());
@@ -109,20 +108,21 @@ public class TestRequestBuilder {
Assert.assertEquals(URI.create("/other-stuff"), copy.getURI());
Assert.assertTrue(copy instanceof HttpEntityEnclosingRequest);
Assert.assertSame(entity, ((HttpEntityEnclosingRequest) copy).getEntity());
- Assert.assertSame(params, copy.getParams());
+ Assert.assertTrue(copy instanceof Configurable);
+ Assert.assertSame(config, ((Configurable) copy).getConfig());
}
@Test
public void testClone() throws Exception {
HttpEntity entity = new StringEntity("stuff");
- HttpParams params = new BasicHttpParams();
+ RequestConfig config = RequestConfig.custom().build();
HttpUriRequest request = RequestBuilder.createPut()
.setUri(URI.create("/stuff"))
.setVersion(HttpVersion.HTTP_1_0)
.addHeader("header1", "stuff")
.setHeader("header2", "more stuff")
.setEntity(entity)
- .setParams(params)
+ .setConfig(config)
.build();
Assert.assertNotNull(request);
Assert.assertEquals("PUT", request.getMethod());
@@ -136,8 +136,8 @@ public class TestRequestBuilder {
Assert.assertTrue(clone instanceof HttpEntityEnclosingRequest);
Assert.assertNotNull(((HttpEntityEnclosingRequest) clone).getEntity());
Assert.assertNotSame(entity, ((HttpEntityEnclosingRequest) clone).getEntity());
- Assert.assertNotNull(clone.getParams());
- Assert.assertNotSame(params, clone.getParams());
+ Assert.assertTrue(clone instanceof Configurable);
+ Assert.assertSame(config, ((Configurable) clone).getConfig());
}
@Test
@@ -151,7 +151,7 @@ public class TestRequestBuilder {
@Test
public void testGettersAndMutators() throws Exception {
HttpEntity entity = new StringEntity("stuff");
- HttpParams params = new BasicHttpParams();
+ RequestConfig config = RequestConfig.custom().build();
Header h1 = new BasicHeader("header1", "stuff");
Header h2 = new BasicHeader("header1", "more-stuff");
RequestBuilder builder = RequestBuilder.createPut()
@@ -160,7 +160,7 @@ public class TestRequestBuilder {
.addHeader(h1)
.addHeader(h2)
.setEntity(entity)
- .setParams(params);
+ .setConfig(config);
Assert.assertEquals("PUT", builder.getMethod());
Assert.assertEquals(URI.create("/stuff"), builder.getUri());
Assert.assertEquals(HttpVersion.HTTP_1_0, builder.getVersion());
@@ -168,7 +168,7 @@ public class TestRequestBuilder {
Assert.assertSame(h2, builder.getLastHeader("header1"));
Assert.assertEquals(2, builder.getHeaders("header1").length);
Assert.assertSame(entity, builder.getEntity());
- Assert.assertSame(params, builder.getParams());
+ Assert.assertSame(config, builder.getConfig());
builder.setMethod(null)
.setUri((String) null)
@@ -177,7 +177,7 @@ public class TestRequestBuilder {
.removeHeaders("header1")
.removeHeader(h2)
.setEntity(null)
- .setParams(null);
+ .setConfig(null);
Assert.assertEquals(null, builder.getMethod());
Assert.assertEquals(null, builder.getUri());
Assert.assertEquals(null, builder.getVersion());
@@ -185,7 +185,7 @@ public class TestRequestBuilder {
Assert.assertSame(null, builder.getLastHeader("header1"));
Assert.assertEquals(0, builder.getHeaders("header1").length);
Assert.assertSame(null, builder.getEntity());
- Assert.assertSame(null, builder.getParams());
+ Assert.assertSame(null, builder.getConfig());
}
}
diff --git a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
index c6eee6282..7f7593fa5 100644
--- a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
+++ b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
@@ -33,8 +33,8 @@ import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.client.CookieStore;
-import org.apache.http.client.params.AllClientPNames;
-import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Lookup;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.routing.HttpRoute;
@@ -84,12 +84,12 @@ public class TestRequestAddCookies {
this.cookieStore.addCookie(cookie2);
this.cookieSpecRegistry = RegistryBuilder.create()
- .register(CookiePolicy.BEST_MATCH, new BestMatchSpecFactory())
- .register(CookiePolicy.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
- .register(CookiePolicy.NETSCAPE, new NetscapeDraftSpecFactory())
- .register(CookiePolicy.RFC_2109, new RFC2109SpecFactory())
- .register(CookiePolicy.RFC_2965, new RFC2965SpecFactory())
- .register(CookiePolicy.IGNORE_COOKIES, new IgnoreSpecFactory())
+ .register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
+ .register(CookieSpecs.BROWSER_COMPATIBILITY, new BrowserCompatSpecFactory())
+ .register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
+ .register(CookieSpecs.RFC_2109, new RFC2109SpecFactory())
+ .register(CookieSpecs.RFC_2965, new RFC2965SpecFactory())
+ .register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory())
.build();
}
@@ -256,13 +256,14 @@ public class TestRequestAddCookies {
@Test
public void testAddCookiesUsingExplicitCookieSpec() throws Exception {
HttpRequest request = new BasicHttpRequest("GET", "/");
- request.getParams().setParameter(AllClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
-
+ RequestConfig config = RequestConfig.custom()
+ .setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
HttpRoute route = new HttpRoute(this.target, null, false);
HttpContext context = new BasicHttpContext();
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, this.target);
context.setAttribute(ClientContext.ROUTE, route);
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
diff --git a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestDefaultHeaders.java b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestDefaultHeaders.java
index 89cf26263..a394381e2 100644
--- a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestDefaultHeaders.java
+++ b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestDefaultHeaders.java
@@ -34,7 +34,6 @@ import junit.framework.Assert;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.client.params.AllClientPNames;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.protocol.BasicHttpContext;
@@ -55,10 +54,9 @@ public class TestRequestDefaultHeaders {
HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");
List defheaders = new ArrayList();
defheaders.add(new BasicHeader("custom", "stuff"));
- request.getParams().setParameter(AllClientPNames.DEFAULT_HEADERS, defheaders);
HttpContext context = new BasicHttpContext();
- HttpRequestInterceptor interceptor = new RequestDefaultHeaders();
+ HttpRequestInterceptor interceptor = new RequestDefaultHeaders(defheaders);
interceptor.process(request, context);
Header header1 = request.getFirstHeader("custom");
Assert.assertNull(header1);
@@ -70,10 +68,9 @@ public class TestRequestDefaultHeaders {
request.addHeader("custom", "stuff");
List defheaders = new ArrayList();
defheaders.add(new BasicHeader("custom", "more stuff"));
- request.getParams().setParameter(AllClientPNames.DEFAULT_HEADERS, defheaders);
HttpContext context = new BasicHttpContext();
- HttpRequestInterceptor interceptor = new RequestDefaultHeaders();
+ HttpRequestInterceptor interceptor = new RequestDefaultHeaders(defheaders);
interceptor.process(request, context);
Header[] headers = request.getHeaders("custom");
Assert.assertNotNull(headers);
diff --git a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestExpectContinue.java b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestExpectContinue.java
new file mode 100644
index 000000000..54041aef3
--- /dev/null
+++ b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestExpectContinue.java
@@ -0,0 +1,126 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.http.client.protocol;
+
+import org.apache.http.Header;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.message.BasicHttpEntityEnclosingRequest;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestRequestExpectContinue {
+
+ @Test
+ public void testRequestExpectContinueGenerated() throws Exception {
+ HttpContext context = new BasicHttpContext();
+ RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
+ BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
+ String s = "whatever";
+ StringEntity entity = new StringEntity(s, "US-ASCII");
+ request.setEntity(entity);
+ RequestExpectContinue interceptor = new RequestExpectContinue();
+ interceptor.process(request, context);
+ Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
+ Assert.assertNotNull(header);
+ Assert.assertEquals(HTTP.EXPECT_CONTINUE, header.getValue());
+ }
+
+ @Test
+ public void testRequestExpectContinueNotGenerated() throws Exception {
+ HttpContext context = new BasicHttpContext(null);
+ RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(false).build();
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
+ BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
+ String s = "whatever";
+ StringEntity entity = new StringEntity(s, "US-ASCII");
+ request.setEntity(entity);
+ RequestExpectContinue interceptor = new RequestExpectContinue();
+ interceptor.process(request, context);
+ Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
+ Assert.assertNull(header);
+ }
+
+ @Test
+ public void testRequestExpectContinueHTTP10() throws Exception {
+ HttpContext context = new BasicHttpContext(null);
+ RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
+ BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
+ "POST", "/", HttpVersion.HTTP_1_0);
+ String s = "whatever";
+ StringEntity entity = new StringEntity(s, "US-ASCII");
+ request.setEntity(entity);
+ RequestExpectContinue interceptor = new RequestExpectContinue();
+ interceptor.process(request, context);
+ Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
+ Assert.assertNull(header);
+ }
+
+ @Test
+ public void testRequestExpectContinueZeroContent() throws Exception {
+ HttpContext context = new BasicHttpContext(null);
+ RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
+ BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
+ String s = "";
+ StringEntity entity = new StringEntity(s, "US-ASCII");
+ request.setEntity(entity);
+ RequestExpectContinue interceptor = new RequestExpectContinue();
+ interceptor.process(request, context);
+ Header header = request.getFirstHeader(HTTP.EXPECT_DIRECTIVE);
+ Assert.assertNull(header);
+ }
+
+ @Test
+ public void testRequestExpectContinueInvalidInput() throws Exception {
+ RequestExpectContinue interceptor = new RequestExpectContinue();
+ try {
+ interceptor.process(null, null);
+ Assert.fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testRequestExpectContinueIgnoreNonenclosingRequests() throws Exception {
+ HttpContext context = new BasicHttpContext(null);
+ BasicHttpRequest request = new BasicHttpRequest("POST", "/");
+ RequestExpectContinue interceptor = new RequestExpectContinue();
+ interceptor.process(request, context);
+ Assert.assertEquals(0, request.getAllHeaders().length);
+ }
+
+}
diff --git a/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java b/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java
index 3aa56431b..1a3a1e76e 100644
--- a/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java
+++ b/httpclient/src/test/java/org/apache/http/impl/auth/TestBasicScheme.java
@@ -27,6 +27,7 @@
package org.apache.http.impl.auth;
import org.apache.commons.codec.binary.Base64;
+import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.auth.AuthScheme;
@@ -62,8 +63,12 @@ public class TestBasicScheme {
buffer.append((char)germanChar);
}
- UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("dh", buffer.toString());
- Header header = BasicScheme.authenticate(credentials, "ISO-8859-1", false);
+ UsernamePasswordCredentials creds = new UsernamePasswordCredentials("dh", buffer.toString());
+ BasicScheme authscheme = new BasicScheme(Consts.ISO_8859_1);
+
+ HttpRequest request = new BasicHttpRequest("GET", "/");
+ HttpContext context = new BasicHttpContext();
+ Header header = authscheme.authenticate(creds, request, context);
Assert.assertEquals("Basic ZGg65C32Lfw=", header.getValue());
}
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java b/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java
index 16682457a..0c675a801 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/TestAuthenticationStrategy.java
@@ -41,10 +41,10 @@ import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.params.AuthPolicy;
+import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
@@ -274,8 +274,10 @@ public class TestAuthenticationStrategy {
public void testCustomAuthPreference() throws Exception {
TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_UNAUTHORIZED, "UNAUTHORIZED");
- response.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
- Arrays.asList(new String[] {AuthPolicy.BASIC } ));
+ RequestConfig config = RequestConfig.custom()
+ .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
+ .build();
+
HttpHost authhost = new HttpHost("somehost", 80);
HttpContext context = new BasicHttpContext();
@@ -287,6 +289,7 @@ public class TestAuthenticationStrategy {
.register("basic", new BasicSchemeFactory())
.register("digest", new DigestSchemeFactory()).build();
context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, authSchemeRegistry);
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope("somehost", 80),
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java b/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java
index deb656db7..0be8a0698 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultRedirectStrategy.java
@@ -35,6 +35,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.ProtocolException;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
@@ -42,7 +43,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpTrace;
import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.client.params.ClientPNames;
+import org.apache.http.client.protocol.ClientContext;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.protocol.BasicHttpContext;
@@ -254,8 +255,10 @@ public class TestDefaultRedirectStrategy {
DefaultRedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
HttpContext context = new BasicHttpContext();
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, new HttpHost("localhost"));
+ RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(false).build();
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
+
HttpGet httpget = new HttpGet("http://localhost/");
- httpget.getParams().setParameter(ClientPNames.REJECT_RELATIVE_REDIRECT, Boolean.TRUE);
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
response.addHeader("Location", "/stuff");
@@ -268,7 +271,8 @@ public class TestDefaultRedirectStrategy {
HttpContext context = new BasicHttpContext();
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, new HttpHost("localhost"));
HttpGet httpget = new HttpGet("http://localhost/");
- httpget.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
+ RequestConfig config = RequestConfig.custom().setCircularRedirectsAllowed(true).build();
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
response.addHeader("Location", "http://localhost/stuff");
@@ -295,7 +299,8 @@ public class TestDefaultRedirectStrategy {
HttpContext context = new BasicHttpContext();
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, new HttpHost("localhost"));
HttpGet httpget = new HttpGet("http://localhost/");
- httpget.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.FALSE);
+ RequestConfig config = RequestConfig.custom().setCircularRedirectsAllowed(false).build();
+ context.setAttribute(ClientContext.REQUEST_CONFIG, config);
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
HttpStatus.SC_MOVED_TEMPORARILY, "Redirect");
response.addHeader("Location", "http://localhost/stuff");
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java
index 64144e2d5..d7ee5e03d 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestAbortHandling.java
@@ -297,6 +297,7 @@ public class TestAbortHandling extends IntegrationTestBase {
Mockito.any(HttpClientConnection.class),
Mockito.any(HttpHost.class),
Mockito.any(InetAddress.class),
+ Mockito.anyInt(),
Mockito.any(HttpContext.class));
Mockito.when(connmgr.requestConnection(
@@ -457,6 +458,7 @@ public class TestAbortHandling extends IntegrationTestBase {
final HttpClientConnection conn,
final HttpHost host,
final InetAddress localAddress,
+ final int connectTimeout,
final HttpContext context) throws IOException {
throw new UnsupportedOperationException("just a mockup");
}
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
index 6ada354c5..d507032ea 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientAuthentication.java
@@ -43,6 +43,7 @@ import org.apache.http.client.AuthCache;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.NonRepeatableRequestException;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
@@ -58,7 +59,6 @@ import org.apache.http.localserver.BasicAuthTokenExtractor;
import org.apache.http.localserver.LocalTestServer;
import org.apache.http.localserver.RequestBasicAuth;
import org.apache.http.localserver.ResponseBasicUnauthorized;
-import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpExpectationVerifier;
@@ -240,12 +240,13 @@ public class TestClientAuthentication extends IntegrationTestBase {
this.httpclient = HttpClients.custom().setCredentialsProvider(credsProvider).build();
+ RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
HttpPut httpput = new HttpPut("/");
+ httpput.setConfig(config);
httpput.setEntity(new InputStreamEntity(
new ByteArrayInputStream(
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
-1));
- httpput.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
HttpResponse response = this.httpclient.execute(getServerHttp(), httpput);
HttpEntity entity = response.getEntity();
@@ -262,12 +263,13 @@ public class TestClientAuthentication extends IntegrationTestBase {
this.httpclient = HttpClients.custom().setCredentialsProvider(credsProvider).build();
+ RequestConfig config = RequestConfig.custom().setExpectContinueEnabled(true).build();
HttpPut httpput = new HttpPut("/");
+ httpput.setConfig(config);
httpput.setEntity(new InputStreamEntity(
new ByteArrayInputStream(
new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
-1));
- httpput.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
try {
this.httpclient.execute(getServerHttp(), httpput);
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
index 200b0a47c..b9acfc56a 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientReauthentication.java
@@ -26,7 +26,7 @@
package org.apache.http.impl.client.integration;
import java.io.IOException;
-import java.util.Collections;
+import java.util.Arrays;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.http.Consts;
@@ -41,8 +41,8 @@ import org.apache.http.auth.AuthScheme;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
@@ -51,7 +51,6 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.TargetAuthenticationStrategy;
import org.apache.http.localserver.LocalTestServer;
import org.apache.http.localserver.RequestBasicAuth;
-import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
@@ -178,18 +177,19 @@ public class TestClientReauthentication extends IntegrationTestBase {
TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
+ RequestConfig config = RequestConfig.custom()
+ .setTargetPreferredAuthSchemes(Arrays.asList("MyBasic"))
+ .build();
this.httpclient = HttpClients.custom()
.registerAuthScheme("MyBasic", myBasicAuthSchemeFactory)
.setTargetAuthenticationStrategy(myAuthStrategy)
.setCredentialsProvider(credsProvider)
.build();
- this.httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
- Collections.singletonList("MyBasic"));
-
HttpContext context = new BasicHttpContext();
for (int i = 0; i < 10; i++) {
HttpGet httpget = new HttpGet("/");
+ httpget.setConfig(config);
HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
HttpEntity entity = response.getEntity();
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
index 716d3672f..aac2d545c 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
@@ -31,7 +31,6 @@ import java.io.IOException;
import org.apache.http.Header;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
@@ -41,7 +40,6 @@ import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.NonRepeatableRequestException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.params.ClientPNames;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
@@ -81,156 +79,6 @@ public class TestClientRequestExecution extends IntegrationTestBase {
}
}
- @Test
- public void testDefaultHostAtClientLevel() throws Exception {
- int port = this.localServer.getServiceAddress().getPort();
- this.localServer.register("*", new SimpleService());
-
- HttpHost target = new HttpHost("localhost", port);
-
- this.httpclient = HttpClients.custom().build();
- this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
-
- String s = "/path";
- HttpGet httpget = new HttpGet(s);
-
- HttpResponse response = this.httpclient.execute(httpget);
- EntityUtils.consume(response.getEntity());
- Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- }
-
- @Test
- public void testDefaultHostHeader() throws Exception {
- int port = this.localServer.getServiceAddress().getPort();
- String hostname = getServerHttp().getHostName();
- this.localServer.register("*", new SimpleService());
-
- HttpContext context = new BasicHttpContext();
-
- String s = "http://localhost:" + port;
- HttpGet httpget = new HttpGet(s);
-
- this.httpclient = HttpClients.custom().build();
- HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
- EntityUtils.consume(response.getEntity());
-
- HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
- ExecutionContext.HTTP_REQUEST);
-
- Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- // Check that Host header is generated as expected
- Header[] headers = reqWrapper.getHeaders("host");
- Assert.assertNotNull(headers);
- Assert.assertEquals(1, headers.length);
- Assert.assertEquals(hostname + ":" + port, headers[0].getValue());
- }
-
- @Test
- // HTTPCLIENT-1092
- public void testVirtualHostHeader() throws Exception {
- int port = this.localServer.getServiceAddress().getPort();
- this.localServer.register("*", new SimpleService());
-
- HttpContext context = new BasicHttpContext();
-
- String s = "http://localhost:" + port;
- HttpGet httpget = new HttpGet(s);
-
- this.httpclient = HttpClients.custom().build();
- String virtHost = "virtual";
- httpget.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, port));
- HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
- EntityUtils.consume(response.getEntity());
-
- HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
- ExecutionContext.HTTP_REQUEST);
-
- Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- // Check that Host header is generated as expected
- Header[] headers = reqWrapper.getHeaders("host");
- Assert.assertNotNull(headers);
- Assert.assertEquals(1, headers.length);
- Assert.assertEquals(virtHost+":"+port,headers[0].getValue());
- }
-
- @Test
- // Test that virtual port is propagated if provided
- // This is not expected to be used much, if ever
- // HTTPCLIENT-1092
- public void testVirtualHostPortHeader() throws Exception {
- int port = this.localServer.getServiceAddress().getPort();
- this.localServer.register("*", new SimpleService());
-
- HttpContext context = new BasicHttpContext();
-
- String s = "http://localhost:" + port;
- HttpGet httpget = new HttpGet(s);
-
- this.httpclient = HttpClients.custom().build();
- String virtHost = "virtual";
- int virtPort = 9876;
- httpget.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, virtPort));
- HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
- EntityUtils.consume(response.getEntity());
-
- HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
- ExecutionContext.HTTP_REQUEST);
-
- Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- // Check that Host header is generated as expected
- Header[] headers = reqWrapper.getHeaders("host");
- Assert.assertNotNull(headers);
- Assert.assertEquals(1, headers.length);
- Assert.assertEquals(virtHost+":"+virtPort,headers[0].getValue());
- }
-
- @Test
- public void testClientLevelVirtualHostHeader() throws Exception {
- int port = this.localServer.getServiceAddress().getPort();
- this.localServer.register("*", new SimpleService());
-
- HttpContext context = new BasicHttpContext();
-
- String s = "http://localhost:" + port;
- HttpGet httpget = new HttpGet(s);
-
- this.httpclient = HttpClients.custom().build();
- String virtHost = "virtual";
- this.httpclient.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(virtHost, port));
- HttpResponse response = this.httpclient.execute(getServerHttp(), httpget, context);
- EntityUtils.consume(response.getEntity());
-
- HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
- ExecutionContext.HTTP_REQUEST);
-
- Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- // Check that Host header is generated as expected
- Header[] headers = reqWrapper.getHeaders("host");
- Assert.assertNotNull(headers);
- Assert.assertEquals(1, headers.length);
- Assert.assertEquals(virtHost+":"+port,headers[0].getValue());
- }
-
- @Test
- public void testDefaultHostAtRequestLevel() throws Exception {
- int port = this.localServer.getServiceAddress().getPort();
- this.localServer.register("*", new SimpleService());
-
- HttpHost target1 = new HttpHost("whatever", 80);
- HttpHost target2 = new HttpHost("localhost", port);
-
- this.httpclient = HttpClients.custom().build();
- this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target1);
-
- String s = "/path";
- HttpGet httpget = new HttpGet(s);
- httpget.getParams().setParameter(ClientPNames.DEFAULT_HOST, target2);
-
- HttpResponse response = this.httpclient.execute(httpget);
- EntityUtils.consume(response.getEntity());
- Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- }
-
private static class FaultyHttpRequestExecutor extends HttpRequestExecutor {
private static final String MARKER = "marker";
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
index de7ba92d8..30c07df4e 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestConnectionManagement.java
@@ -112,7 +112,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
HttpContext context = new BasicHttpContext();
HttpClientConnection conn = getConnection(mgr, route);
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
@@ -146,7 +146,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
conn = getConnection(mgr, route);
Assert.assertFalse("connection should have been closed", conn.isOpen());
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
// repeat the communication, no need to prepare the request again
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
@@ -200,7 +200,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
HttpContext context = new BasicHttpContext();
HttpClientConnection conn = getConnection(mgr, route);
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
@@ -235,7 +235,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
Assert.assertFalse("connection should have been closed", conn.isOpen());
// repeat the communication, no need to prepare the request again
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
response = exec.execute(request, conn, context);
@@ -270,7 +270,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
Assert.assertTrue("connection should have been closed", !conn.isOpen());
// repeat the communication, no need to prepare the request again
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
response = exec.execute(request, conn, context);
@@ -297,7 +297,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
HttpContext context = new BasicHttpContext();
HttpClientConnection conn = getConnection(mgr, route);
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
Assert.assertEquals(1, mgr.getStats(route).getLeased());
@@ -337,7 +337,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
HttpContext context = new BasicHttpContext();
HttpClientConnection conn = getConnection(mgr, route);
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
Assert.assertEquals(1, mgr.getTotalStats().getLeased());
Assert.assertEquals(1, mgr.getStats(route).getLeased());
@@ -385,7 +385,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);
HttpClientConnection conn = getConnection(mgr, route);
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
@@ -457,7 +457,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
abortingThread.start();
try {
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
Assert.fail("expected SocketException");
} catch(SocketException expected) {}
@@ -510,7 +510,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
abortingThread.start();
try {
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
Assert.fail("IOException expected");
} catch(IOException expected) {
}
@@ -564,7 +564,7 @@ public class TestConnectionManagement extends LocalServerTestBase {
abortingThread.start();
try {
- mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), context);
+ mgr.connect(conn, route.getTargetHost(), route.getLocalAddress(), 0, context);
Assert.fail("IOException expected");
} catch(IOException expected) {
}
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java
index 5f73b0b5b..cb17eb4a2 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestCookie2Support.java
@@ -37,8 +37,6 @@ import org.apache.http.HttpStatus;
import org.apache.http.ProtocolVersion;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.SM;
@@ -64,7 +62,7 @@ public class TestCookie2Support extends IntegrationTestBase {
@Before
public void setUp() throws Exception {
startServer();
- this.httpclient = HttpClients.custom().build();
+ this.httpclient = HttpClients.createDefault();
}
private static class CookieVer0Service implements HttpRequestHandler {
@@ -86,8 +84,6 @@ public class TestCookie2Support extends IntegrationTestBase {
public void testCookieVersionSupportHeader1() throws Exception {
this.localServer.register("*", new CookieVer0Service());
- this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
-
CookieStore cookieStore = new BasicCookieStore();
HttpContext context = new BasicHttpContext();
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
@@ -133,8 +129,6 @@ public class TestCookie2Support extends IntegrationTestBase {
public void testCookieVersionSupportHeader2() throws Exception {
this.localServer.register("*", new CookieVer1Service());
- this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
-
CookieStore cookieStore = new BasicCookieStore();
HttpContext context = new BasicHttpContext();
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
@@ -179,8 +173,6 @@ public class TestCookie2Support extends IntegrationTestBase {
public void testCookieVersionSupportHeader3() throws Exception {
this.localServer.register("*", new CookieVer2Service());
- this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
-
CookieStore cookieStore = new BasicCookieStore();
HttpContext context = new BasicHttpContext();
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
@@ -226,8 +218,6 @@ public class TestCookie2Support extends IntegrationTestBase {
public void testSetCookieVersionMix() throws Exception {
this.localServer.register("*", new SetCookieVersionMixService());
- this.httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
-
CookieStore cookieStore = new BasicCookieStore();
HttpContext context = new BasicHttpContext();
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java
index 2f33a54a7..1e1a93166 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestRedirects.java
@@ -27,8 +27,7 @@
package org.apache.http.impl.client.integration;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Arrays;
import org.apache.http.Header;
import org.apache.http.HttpException;
@@ -43,9 +42,9 @@ import org.apache.http.client.CircularRedirectException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.RedirectException;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.cookie.SM;
import org.apache.http.entity.StringEntity;
@@ -400,10 +399,13 @@ public class TestRedirects extends IntegrationTestBase {
HttpHost target = getServerHttp();
this.localServer.register("*", new CircularRedirectService());
- this.httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
- this.httpclient.getParams().setIntParameter(ClientPNames.MAX_REDIRECTS, 5);
+ RequestConfig config = RequestConfig.custom()
+ .setCircularRedirectsAllowed(true)
+ .setMaxRedirects(5)
+ .build();
HttpGet httpget = new HttpGet("/circular-oldlocation/");
+ httpget.setConfig(config);
try {
this.httpclient.execute(target, httpget);
} catch (ClientProtocolException e) {
@@ -417,10 +419,12 @@ public class TestRedirects extends IntegrationTestBase {
HttpHost target = getServerHttp();
this.localServer.register("*", new CircularRedirectService());
- this.httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false);
+ RequestConfig config = RequestConfig.custom()
+ .setCircularRedirectsAllowed(false)
+ .build();
HttpGet httpget = new HttpGet("/circular-oldlocation/");
-
+ httpget.setConfig(config);
try {
this.httpclient.execute(target, httpget);
} catch (ClientProtocolException e) {
@@ -478,9 +482,9 @@ public class TestRedirects extends IntegrationTestBase {
HttpContext context = new BasicHttpContext();
- this.httpclient.getParams().setBooleanParameter(
- ClientPNames.REJECT_RELATIVE_REDIRECT, false);
+ RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(true).build();
HttpGet httpget = new HttpGet("/oldlocation/");
+ httpget.setConfig(config);
HttpResponse response = this.httpclient.execute(target, httpget, context);
EntityUtils.consume(response.getEntity());
@@ -502,9 +506,9 @@ public class TestRedirects extends IntegrationTestBase {
HttpContext context = new BasicHttpContext();
- this.httpclient.getParams().setBooleanParameter(
- ClientPNames.REJECT_RELATIVE_REDIRECT, false);
+ RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(true).build();
HttpGet httpget = new HttpGet("/test/oldlocation");
+ httpget.setConfig(config);
HttpResponse response = this.httpclient.execute(target, httpget, context);
EntityUtils.consume(response.getEntity());
@@ -524,10 +528,9 @@ public class TestRedirects extends IntegrationTestBase {
HttpHost target = getServerHttp();
this.localServer.register("*", new RelativeRedirectService());
- this.httpclient.getParams().setBooleanParameter(
- ClientPNames.REJECT_RELATIVE_REDIRECT, true);
+ RequestConfig config = RequestConfig.custom().setRelativeRedirectsAllowed(false).build();
HttpGet httpget = new HttpGet("/oldlocation/");
-
+ httpget.setConfig(config);
try {
this.httpclient.execute(target, httpget);
} catch (ClientProtocolException e) {
@@ -597,17 +600,15 @@ public class TestRedirects extends IntegrationTestBase {
@Test
public void testDefaultHeadersRedirect() throws Exception {
+ this.httpclient = HttpClients.custom()
+ .setDefaultHeaders(Arrays.asList(new BasicHeader(HTTP.USER_AGENT, "my-test-client")))
+ .build();
HttpHost target = getServerHttp();
this.localServer.register("*", new BasicRedirectService());
HttpContext context = new BasicHttpContext();
- List defaultHeaders = new ArrayList(1);
- defaultHeaders.add(new BasicHeader(HTTP.USER_AGENT, "my-test-client"));
-
- this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HEADERS, defaultHeaders);
-
HttpGet httpget = new HttpGet("/oldlocation/");
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
index 8240f2ee1..4ec1a801d 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
@@ -35,19 +35,17 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AuthScheme;
+import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.AuthSchemes;
import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.params.AuthPolicy;
-import org.apache.http.client.params.ClientPNames;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.SPNegoScheme;
-import org.apache.http.impl.auth.SPNegoSchemeFactory;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
-import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.util.EntityUtils;
@@ -132,16 +130,15 @@ public class TestSPNegoScheme extends IntegrationTestBase {
}
- private static class NegotiateSchemeFactoryWithMockGssManager extends SPNegoSchemeFactory {
+ private static class NegotiateSchemeProviderWithMockGssManager implements AuthSchemeProvider {
NegotiateSchemeWithMockGssManager scheme;
- NegotiateSchemeFactoryWithMockGssManager() throws Exception {
+ NegotiateSchemeProviderWithMockGssManager() throws Exception {
scheme = new NegotiateSchemeWithMockGssManager();
}
- @Override
- public AuthScheme newInstance(HttpParams params) {
+ public AuthScheme create(HttpContext context) {
return scheme;
}
@@ -158,21 +155,19 @@ public class TestSPNegoScheme extends IntegrationTestBase {
HttpHost target = new HttpHost("localhost", port);
- SPNegoSchemeFactory nsf = new NegotiateSchemeFactoryWithMockGssManager();
+ AuthSchemeProvider nsf = new NegotiateSchemeProviderWithMockGssManager();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
Credentials use_jaas_creds = new UseJaasCredentials();
credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);
this.httpclient = HttpClients.custom()
- .registerAuthScheme(AuthPolicy.SPNEGO, nsf)
+ .registerAuthScheme(AuthSchemes.SPNEGO, nsf)
.setCredentialsProvider(credentialsProvider)
.build();
- this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
-
String s = "/path";
HttpGet httpget = new HttpGet(s);
- HttpResponse response = this.httpclient.execute(httpget);
+ HttpResponse response = this.httpclient.execute(target, httpget);
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
@@ -189,21 +184,20 @@ public class TestSPNegoScheme extends IntegrationTestBase {
HttpHost target = new HttpHost("localhost", port);
- NegotiateSchemeFactoryWithMockGssManager nsf = new NegotiateSchemeFactoryWithMockGssManager();
+ AuthSchemeProvider nsf = new NegotiateSchemeProviderWithMockGssManager();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
Credentials use_jaas_creds = new UseJaasCredentials();
credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);
this.httpclient = HttpClients.custom()
- .registerAuthScheme(AuthPolicy.SPNEGO, nsf)
+ .registerAuthScheme(AuthSchemes.SPNEGO, nsf)
.setCredentialsProvider(credentialsProvider)
.build();
- this.httpclient.getParams().setParameter(ClientPNames.DEFAULT_HOST, target);
String s = "/path";
HttpGet httpget = new HttpGet(s);
- HttpResponse response = this.httpclient.execute(httpget);
+ HttpResponse response = this.httpclient.execute(target, httpget);
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
index 53a4f44a9..40ab196f5 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
@@ -39,9 +39,6 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
@@ -88,9 +85,6 @@ public class TestStatefulConnManagement extends IntegrationTestBase {
HttpHost target = new HttpHost("localhost", port);
- HttpParams params = new BasicHttpParams();
- HttpConnectionParams.setConnectionTimeout(params, 10);
-
PoolingHttpClientConnectionManager mgr = new PoolingHttpClientConnectionManager();
mgr.setMaxTotal(workerCount);
mgr.setDefaultMaxPerRoute(workerCount);
diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java b/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java
index 5b7bd163b..1dc28213d 100644
--- a/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java
+++ b/httpclient/src/test/java/org/apache/http/impl/conn/TestDefaultRoutePlanner.java
@@ -33,6 +33,8 @@ import org.apache.http.HttpVersion;
import org.apache.http.conn.SchemePortResolver;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -57,7 +59,8 @@ public class TestDefaultRoutePlanner {
HttpHost target = new HttpHost("somehost", 80, "http");
HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
- HttpRoute route = routePlanner.determineRoute(target, request, null);
+ HttpContext context = new BasicHttpContext();
+ HttpRoute route = routePlanner.determineRoute(target, request, context);
Assert.assertEquals(target, route.getTargetHost());
Assert.assertEquals(1, route.getHopCount());
@@ -71,7 +74,8 @@ public class TestDefaultRoutePlanner {
Mockito.when(schemePortResolver.resolve(target)).thenReturn(443);
HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
- HttpRoute route = routePlanner.determineRoute(target, request, null);
+ HttpContext context = new BasicHttpContext();
+ HttpRoute route = routePlanner.determineRoute(target, request, context);
Assert.assertEquals(new HttpHost("somehost", 443, "https"), route.getTargetHost());
Assert.assertEquals(1, route.getHopCount());
diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java b/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
index be3c21402..927f0ba05 100644
--- a/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
+++ b/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
@@ -41,6 +41,8 @@ import org.apache.http.HttpVersion;
import org.apache.http.conn.SchemePortResolver;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -67,7 +69,8 @@ public class TestSystemDefaultRoutePlanner {
HttpHost target = new HttpHost("somehost", 80, "http");
HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
- HttpRoute route = routePlanner.determineRoute(target, request, null);
+ HttpContext context = new BasicHttpContext();
+ HttpRoute route = routePlanner.determineRoute(target, request, context);
Assert.assertEquals(target, route.getTargetHost());
Assert.assertEquals(1, route.getHopCount());
@@ -81,7 +84,8 @@ public class TestSystemDefaultRoutePlanner {
Mockito.when(schemePortResolver.resolve(target)).thenReturn(443);
HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
- HttpRoute route = routePlanner.determineRoute(target, request, null);
+ HttpContext context = new BasicHttpContext();
+ HttpRoute route = routePlanner.determineRoute(target, request, context);
Assert.assertEquals(new HttpHost("somehost", 443, "https"), route.getTargetHost());
Assert.assertEquals(1, route.getHopCount());
@@ -107,7 +111,8 @@ public class TestSystemDefaultRoutePlanner {
HttpRequest request =
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
- HttpRoute route = routePlanner.determineRoute(target, request, null);
+ HttpContext context = new BasicHttpContext();
+ HttpRoute route = routePlanner.determineRoute(target, request, context);
Assert.assertEquals(target, route.getTargetHost());
Assert.assertEquals(2, route.getHopCount());