From 804d75f23c22a750a8f96fa044bc9c910e8ad0f1 Mon Sep 17 00:00:00 2001 From: Roland Weber Date: Wed, 21 Feb 2007 16:12:28 +0000 Subject: [PATCH] fixed revised fix for default port, fixed target host in context, updated client examples git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@510081 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/examples/client/ClientExecuteDirect.java | 10 ++-------- .../http/examples/client/ClientExecuteProxy.java | 10 ++-------- .../http/impl/client/DefaultClientRequestDirector.java | 3 +++ .../impl/conn/DefaultClientConnectionOperator.java | 6 +++--- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java b/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java index d033c6cca..b5378de7b 100644 --- a/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java +++ b/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java @@ -102,7 +102,7 @@ public class ClientExecuteDirect { HttpClient client = createHttpClient(); - HttpRequest req = createRequest(target); + HttpRequest req = createRequest(); System.out.println("executing request to " + target); HttpEntity entity = null; @@ -187,21 +187,15 @@ public class ClientExecuteDirect { /** * Creates a request to execute in this example. - * In a real application, request interceptors should be used - * to add the required headers. - * - * @param target the target server for the request * * @return a request without an entity */ - private final static HttpRequest createRequest(HttpHost target) { + private final static HttpRequest createRequest() { HttpRequest req = new BasicHttpRequest ("GET", "/", HttpVersion.HTTP_1_1); //("OPTIONS", "*", HttpVersion.HTTP_1_1); - req.addHeader("Host", target.getHostName()); - return req; } diff --git a/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java b/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java index 763b11f26..b6191c115 100644 --- a/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java +++ b/src/examples/org/apache/http/examples/client/ClientExecuteProxy.java @@ -109,7 +109,7 @@ public class ClientExecuteProxy { HttpClient client = createHttpClient(); - HttpRequest req = createRequest(target); + HttpRequest req = createRequest(); final HttpRoute route = new HttpRoute (target, null, proxy, @@ -201,21 +201,15 @@ public class ClientExecuteProxy { /** * Creates a request to execute in this example. - * In a real application, request interceptors should be used - * to add the required headers. - * - * @param target the target server for the request * * @return a request without an entity */ - private final static HttpRequest createRequest(HttpHost target) { + private final static HttpRequest createRequest() { HttpRequest req = new BasicHttpRequest ("GET", "/", HttpVersion.HTTP_1_1); //("OPTIONS", "*", HttpVersion.HTTP_1_1); - req.addHeader("Host", target.getHostName()); - return req; } diff --git a/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java b/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java index cc3d8960c..45b6cbc03 100644 --- a/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java +++ b/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java @@ -44,6 +44,7 @@ import org.apache.http.message.BasicHttpRequest; import org.apache.http.params.HttpParams; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpRequestExecutor; +import org.apache.http.protocol.HttpExecutionContext; import org.apache.http.conn.HttpRoute; import org.apache.http.conn.RouteDirector; import org.apache.http.conn.ClientConnectionManager; @@ -132,6 +133,8 @@ public class DefaultClientRequestDirector HttpRequest prepreq = prepareRequest(roureq, context); //@@@ handle authentication here or via interceptor? + context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, + roureq.getRoute().getTargetHost()); response = requestExec.execute(prepreq, managedConn, context); RoutedRequest followup = diff --git a/src/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java b/src/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java index de0e8e23c..4f3ceb9a2 100644 --- a/src/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java +++ b/src/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java @@ -134,9 +134,9 @@ public class DefaultClientConnectionOperator Socket sock = sf.createSocket(); conn.announce(sock); - sock = sf.connectSocket - (sock, target.getHostName(), target.resolvePort(), - local, 0, params); + sock = sf.connectSocket(sock, target.getHostName(), + schm.resolvePort(target.getPort()), + local, 0, params); prepareSocket(sock, context, params); final boolean secure = sf.isSecure(sock);