Added default host and default proxy parameters HTTP client can fall back onto when determining request route

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@537750 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2007-05-14 08:42:09 +00:00
parent 4f2187386b
commit c82115dd8c
2 changed files with 43 additions and 12 deletions

View File

@ -61,14 +61,6 @@ public class HttpClientParams {
*/ */
public static final String CONNECTION_MANAGER_FACTORY = "http.connection-manager.factory"; public static final String CONNECTION_MANAGER_FACTORY = "http.connection-manager.factory";
/**
* Defines whether authentication should be attempted preemptively.
* <p>
* This parameter expects a value of type {@link Boolean}.
* </p>
*/
public static final String PREEMPTIVE_AUTHENTICATION = "http.authentication.preemptive";
/** /**
* Defines whether redirects should be handled automatically * Defines whether redirects should be handled automatically
* <p> * <p>
@ -104,6 +96,22 @@ public class HttpClientParams {
*/ */
public static final String ALLOW_CIRCULAR_REDIRECTS = "http.protocol.allow-circular-redirects"; public static final String ALLOW_CIRCULAR_REDIRECTS = "http.protocol.allow-circular-redirects";
/**
* Defines whether authentication should be handled automatically.
* <p>
* This parameter expects a value of type {@link Boolean}.
* </p>
*/
public static final String HANDLE_AUTHENTICATION = "http.protocol.handle-authentication";
/**
* Defines whether authentication should be attempted preemptively.
* <p>
* This parameter expects a value of type {@link Boolean}.
* </p>
*/
public static final String PREEMPTIVE_AUTHENTICATION = "http.protocol.authentication-preemptive";
/** /**
* Defines the name of the cookie specification to be used for HTTP state management. * Defines the name of the cookie specification to be used for HTTP state management.
* <p> * <p>
@ -121,6 +129,24 @@ public class HttpClientParams {
*/ */
public static final String DEFAULT_HEADERS = "http.default-headers"; public static final String DEFAULT_HEADERS = "http.default-headers";
/**
* Defines the default host. The default value will be used if the target host is
* not explicitly specified in the request URI.
* <p>
* This parameter expects a value of type {@link HttpHost}.
* </p>
*/
public static final String DEFAULT_HOST = "http.default-host";
/**
* Defines the default proxy. The default value will be used if the proxy
* information is not explicitly specified in the request route.
* <p>
* This parameter expects a value of type {@link HttpHost}.
* </p>
*/
public static final String DEFAULT_PROXY = "http.default-proxy";
private HttpClientParams() { private HttpClientParams() {
super(); super();
} }

View File

@ -244,18 +244,23 @@ public class DefaultHttpClient extends AbstractHttpClient {
HttpContext context) HttpContext context)
throws HttpException { throws HttpException {
//@@@ refer to a default HostConfiguration?
//@@@ allow null target if there is a default route with a target?
if (target == null) { if (target == null) {
throw new IllegalArgumentException target = (HttpHost) request.getParams().getParameter(
HttpClientParams.DEFAULT_HOST);
}
if (target == null) {
throw new IllegalStateException
("Target host must not be null."); ("Target host must not be null.");
} }
HttpHost proxy = (HttpHost) request.getParams().getParameter(
HttpClientParams.DEFAULT_PROXY);
Scheme schm = getConnectionManager().getSchemeRegistry(). Scheme schm = getConnectionManager().getSchemeRegistry().
getScheme(target.getSchemeName()); getScheme(target.getSchemeName());
// as it is typically used for TLS/SSL, we assume that // as it is typically used for TLS/SSL, we assume that
// a layered scheme implies a secure connection // a layered scheme implies a secure connection
HttpRoute route = new HttpRoute(target, null, schm.isLayered()); HttpRoute route = new HttpRoute(target, null, proxy, schm.isLayered());
return new RoutedRequest.Impl(request, route); return new RoutedRequest.Impl(request, route);
} }