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
This commit is contained in:
parent
93fa6c7de1
commit
804d75f23c
|
@ -102,7 +102,7 @@ public class ClientExecuteDirect {
|
||||||
|
|
||||||
HttpClient client = createHttpClient();
|
HttpClient client = createHttpClient();
|
||||||
|
|
||||||
HttpRequest req = createRequest(target);
|
HttpRequest req = createRequest();
|
||||||
|
|
||||||
System.out.println("executing request to " + target);
|
System.out.println("executing request to " + target);
|
||||||
HttpEntity entity = null;
|
HttpEntity entity = null;
|
||||||
|
@ -187,21 +187,15 @@ public class ClientExecuteDirect {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a request to execute in this example.
|
* 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
|
* @return a request without an entity
|
||||||
*/
|
*/
|
||||||
private final static HttpRequest createRequest(HttpHost target) {
|
private final static HttpRequest createRequest() {
|
||||||
|
|
||||||
HttpRequest req = new BasicHttpRequest
|
HttpRequest req = new BasicHttpRequest
|
||||||
("GET", "/", HttpVersion.HTTP_1_1);
|
("GET", "/", HttpVersion.HTTP_1_1);
|
||||||
//("OPTIONS", "*", HttpVersion.HTTP_1_1);
|
//("OPTIONS", "*", HttpVersion.HTTP_1_1);
|
||||||
|
|
||||||
req.addHeader("Host", target.getHostName());
|
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class ClientExecuteProxy {
|
||||||
|
|
||||||
HttpClient client = createHttpClient();
|
HttpClient client = createHttpClient();
|
||||||
|
|
||||||
HttpRequest req = createRequest(target);
|
HttpRequest req = createRequest();
|
||||||
|
|
||||||
final HttpRoute route = new HttpRoute
|
final HttpRoute route = new HttpRoute
|
||||||
(target, null, proxy,
|
(target, null, proxy,
|
||||||
|
@ -201,21 +201,15 @@ public class ClientExecuteProxy {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a request to execute in this example.
|
* 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
|
* @return a request without an entity
|
||||||
*/
|
*/
|
||||||
private final static HttpRequest createRequest(HttpHost target) {
|
private final static HttpRequest createRequest() {
|
||||||
|
|
||||||
HttpRequest req = new BasicHttpRequest
|
HttpRequest req = new BasicHttpRequest
|
||||||
("GET", "/", HttpVersion.HTTP_1_1);
|
("GET", "/", HttpVersion.HTTP_1_1);
|
||||||
//("OPTIONS", "*", HttpVersion.HTTP_1_1);
|
//("OPTIONS", "*", HttpVersion.HTTP_1_1);
|
||||||
|
|
||||||
req.addHeader("Host", target.getHostName());
|
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.apache.http.message.BasicHttpRequest;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.protocol.HttpRequestExecutor;
|
import org.apache.http.protocol.HttpRequestExecutor;
|
||||||
|
import org.apache.http.protocol.HttpExecutionContext;
|
||||||
import org.apache.http.conn.HttpRoute;
|
import org.apache.http.conn.HttpRoute;
|
||||||
import org.apache.http.conn.RouteDirector;
|
import org.apache.http.conn.RouteDirector;
|
||||||
import org.apache.http.conn.ClientConnectionManager;
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
@ -132,6 +133,8 @@ public class DefaultClientRequestDirector
|
||||||
HttpRequest prepreq = prepareRequest(roureq, context);
|
HttpRequest prepreq = prepareRequest(roureq, context);
|
||||||
//@@@ handle authentication here or via interceptor?
|
//@@@ handle authentication here or via interceptor?
|
||||||
|
|
||||||
|
context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST,
|
||||||
|
roureq.getRoute().getTargetHost());
|
||||||
response = requestExec.execute(prepreq, managedConn, context);
|
response = requestExec.execute(prepreq, managedConn, context);
|
||||||
|
|
||||||
RoutedRequest followup =
|
RoutedRequest followup =
|
||||||
|
|
|
@ -134,9 +134,9 @@ public class DefaultClientConnectionOperator
|
||||||
Socket sock = sf.createSocket();
|
Socket sock = sf.createSocket();
|
||||||
conn.announce(sock);
|
conn.announce(sock);
|
||||||
|
|
||||||
sock = sf.connectSocket
|
sock = sf.connectSocket(sock, target.getHostName(),
|
||||||
(sock, target.getHostName(), target.resolvePort(),
|
schm.resolvePort(target.getPort()),
|
||||||
local, 0, params);
|
local, 0, params);
|
||||||
prepareSocket(sock, context, params);
|
prepareSocket(sock, context, params);
|
||||||
|
|
||||||
final boolean secure = sf.isSecure(sock);
|
final boolean secure = sf.isSecure(sock);
|
||||||
|
|
Loading…
Reference in New Issue