diff --git a/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java b/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java index 3b54d8b48..2a58edebc 100644 --- a/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java +++ b/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java @@ -39,7 +39,9 @@ import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; import org.apache.http.client.HttpClient; +import org.apache.http.client.RoutedRequest; import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.HttpRoute; import org.apache.http.conn.PlainSocketFactory; import org.apache.http.conn.Scheme; import org.apache.http.conn.SchemeRegistry; @@ -96,10 +98,13 @@ public class ClientExecuteDirect { HttpRequest req = createRequest(); + final HttpRoute route = new HttpRoute(target, null, false); + final RoutedRequest roureq = new RoutedRequest.Impl(req, route); + System.out.println("executing request to " + target); HttpEntity entity = null; try { - HttpResponse rsp = client.execute(target, req); + HttpResponse rsp = client.execute(roureq, null); entity = rsp.getEntity(); System.out.println("----------------------------------------"); diff --git a/src/examples/org/apache/http/examples/client/MethodAbort.java b/src/examples/org/apache/http/examples/client/MethodAbort.java index 8c0e330a9..bb0cab107 100644 --- a/src/examples/org/apache/http/examples/client/MethodAbort.java +++ b/src/examples/org/apache/http/examples/client/MethodAbort.java @@ -32,7 +32,6 @@ package org.apache.http.examples.client; import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.HttpVersion; import org.apache.http.client.HttpClient; @@ -62,12 +61,10 @@ public class MethodAbort { HttpClient httpclient = new DefaultHttpClient(params); - HttpHost target = new HttpHost("www.apache.org", 80, "http"); + HttpGet httpget = new HttpGet("http://www.apache.org/"); - HttpGet httpget = new HttpGet("/"); - - System.out.println("executing request to " + target); - HttpResponse response = httpclient.execute(target, httpget); + System.out.println("executing request " + httpget.getURI()); + HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); diff --git a/src/java/org/apache/http/client/HttpClient.java b/src/java/org/apache/http/client/HttpClient.java index eec89bf94..93c1fd6d9 100644 --- a/src/java/org/apache/http/client/HttpClient.java +++ b/src/java/org/apache/http/client/HttpClient.java @@ -39,6 +39,7 @@ import org.apache.http.HttpResponse; import org.apache.http.HttpException; import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; +import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.conn.ClientConnectionManager; @@ -94,14 +95,11 @@ public interface HttpClient { ; /** - * Executes a request for the given target using the - * {@link #getContext default context}. - * Same as {@link #execute(HttpHost,HttpRequest,HttpContext) - * client.execute(target, request, client.getContext())}, + * Executes a request using the {@link #getContext default context}. + * Same as {@link #execute(HttpUriRequest,HttpContext) + * client.execute(request, client.getContext())}, * see there for details. * - * @param target the target host for the request. - * Some implementations may accept null. * @param request the request to execute * * @return the response to the request @@ -110,17 +108,15 @@ public interface HttpClient { * @throws IOException in case of an IO problem *
timeout exceptions? */ - HttpResponse execute(HttpHost target, HttpRequest request) + HttpResponse execute(HttpUriRequest request) throws HttpException, IOException ; /** - * Executes a request for the given target using the given context. + * Executes a request using the given context. * The route to the target will be determined by the HTTP client. * - * @param target the target host for the request. - * Some implementations may accept null. * @param request the request to execute * @param context the context to use for the execution, or * null to use the @@ -136,8 +132,7 @@ public interface HttpClient { * @throws IOException in case of an IO problem *
timeout exceptions? */ - HttpResponse execute(HttpHost target, HttpRequest request, - HttpContext context) + HttpResponse execute(HttpUriRequest request, HttpContext context) throws HttpException, IOException ; diff --git a/src/java/org/apache/http/client/methods/HttpRequestBase.java b/src/java/org/apache/http/client/methods/HttpRequestBase.java index dcce0be86..48b6f4114 100644 --- a/src/java/org/apache/http/client/methods/HttpRequestBase.java +++ b/src/java/org/apache/http/client/methods/HttpRequestBase.java @@ -34,7 +34,6 @@ package org.apache.http.client.methods; import java.io.IOException; import java.net.URI; -import org.apache.http.HttpRequest; import org.apache.http.HttpVersion; import org.apache.http.RequestLine; import org.apache.http.conn.ConnectionReleaseTrigger; @@ -52,7 +51,7 @@ import org.apache.http.params.HttpProtocolParams; * @since 4.0 */ abstract class HttpRequestBase extends AbstractHttpMessage - implements HttpRequest, AbortableHttpRequest { + implements HttpUriRequest, AbortableHttpRequest { private URI uri; private ConnectionReleaseTrigger releaseTrigger; diff --git a/src/java/org/apache/http/client/protocol/RequestAddCookies.java b/src/java/org/apache/http/client/protocol/RequestAddCookies.java index 933079a00..e53453c09 100644 --- a/src/java/org/apache/http/client/protocol/RequestAddCookies.java +++ b/src/java/org/apache/http/client/protocol/RequestAddCookies.java @@ -131,9 +131,15 @@ public class RequestAddCookies implements HttpRequestInterceptor { } } + String hostName = targetHost.getHostName(); + int port = targetHost.getPort(); + if (port < 0) { + port = conn.getRemotePort(); + } + CookieOrigin cookieOrigin = new CookieOrigin( - targetHost.getHostName(), - targetHost.getPort(), + hostName, + port, requestURI.getPath(), conn.isSecure()); diff --git a/src/java/org/apache/http/impl/client/AbstractHttpClient.java b/src/java/org/apache/http/impl/client/AbstractHttpClient.java index 0a7ee0be5..c26886506 100644 --- a/src/java/org/apache/http/impl/client/AbstractHttpClient.java +++ b/src/java/org/apache/http/impl/client/AbstractHttpClient.java @@ -32,6 +32,7 @@ package org.apache.http.impl.client; import java.io.IOException; +import java.net.URI; import java.util.List; import org.apache.http.ConnectionReuseStrategy; @@ -47,6 +48,7 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.HttpRequestRetryHandler; import org.apache.http.client.HttpState; import org.apache.http.client.RoutedRequest; +import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.cookie.CookieSpecRegistry; import org.apache.http.params.HttpParams; @@ -304,11 +306,9 @@ public abstract class AbstractHttpClient /** - * Maps to {@link #execute(HttpHost,HttpRequest,HttpContext) - * execute(target, request, context)}. + * Maps to {@link #execute(HttpUriRequest,HttpContext) + * execute(request, context)}. * - * @param target the target host for the request. - * Some implementations may accept null. * @param request the request to execute * * @return the response to the request @@ -316,10 +316,10 @@ public abstract class AbstractHttpClient * @throws HttpException in case of a problem * @throws IOException in case of an IO problem */ - public final HttpResponse execute(HttpHost target, HttpRequest request) + public final HttpResponse execute(HttpUriRequest request) throws HttpException, IOException { - return execute(target, request, null); + return execute(request, null); } @@ -332,17 +332,26 @@ public abstract class AbstractHttpClient * Some implementations may accept null. * @param request the request to execute */ - public final HttpResponse execute(HttpHost target, HttpRequest request, - HttpContext context) + public final HttpResponse execute(HttpUriRequest request, HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException ("Request must not be null."); } + // A null target may be acceptable if there is a default target. // Otherwise, the null target is detected in determineRoute(). - + HttpHost target = null; + + URI requestURI = request.getURI(); + if (requestURI.isAbsolute()) { + target = new HttpHost( + requestURI.getHost(), + requestURI.getPort(), + requestURI.getScheme()); + } + synchronized (this) { if (context == null) { context = new HttpExecutionContext(getContext());