* Minor bug fixes

* Reviewed HTTP CONNECT logic for compliance with Tunneling TCP based protocols through Web proxy servers

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@537590 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2007-05-13 14:46:12 +00:00
parent 69fa4fa732
commit d3fee30940
3 changed files with 34 additions and 14 deletions

View File

@ -175,7 +175,7 @@ public class SSLSocketFactory implements SecureSocketFactory {
}
TrustManager[] trustmanagers = null;
if (truststore != null) {
trustmanagers = createTrustManagers(keystore);
trustmanagers = createTrustManagers(truststore);
}
this.sslcontext = SSLContext.getInstance(algorithm);
this.sslcontext.init(keymanagers, trustmanagers, random);

View File

@ -69,10 +69,13 @@ import org.apache.http.conn.SchemeRegistry;
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.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpExecutionContext;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.util.CharArrayBuffer;
/**
* Default implementation of a client-side request director.
@ -481,17 +484,34 @@ public class DefaultClientRequestDirector
*/
protected HttpRequest createConnectRequest(HttpRoute route,
HttpContext context) {
// see RFC 2817, section 5.2
final String authority =
route.getTargetHost().getHostName() + ":" +
route.getTargetHost().getPort();
//@@@ do we need a more refined algorithm to choose the HTTP version?
//@@@ use a request factory provided by the caller/creator?
// see RFC 2817, section 5.2 and
// INTERNET-DRAFT: Tunneling TCP based protocols through
// Web proxy servers
HttpHost target = route.getTargetHost();
String host = target.getHostName();
int port = target.getPort();
if (port < 0) {
SchemeRegistry schemeREgistry = connManager.getSchemeRegistry();
Scheme scheme = schemeREgistry.getScheme(target.getSchemeName());
port = scheme.getDefaultPort();
}
CharArrayBuffer buffer = new CharArrayBuffer(host.length() + 6);
buffer.append(host);
buffer.append(":");
buffer.append(Integer.toString(port));
String authority = buffer.toString();
HttpVersion ver = HttpProtocolParams.getVersion(params);
HttpRequest req = new BasicHttpRequest
("CONNECT", authority, HttpVersion.HTTP_1_1);
("CONNECT", authority, ver);
req.addHeader("Host", authority);
String agent = HttpProtocolParams.getUserAgent(params);
if (agent != null) {
req.addHeader(HTTP.USER_AGENT, agent);
}
//@@@ authenticate here, in caller, or in request interceptor?

View File

@ -204,10 +204,10 @@ public class DefaultClientConnection extends SocketHttpClientConnection
final HttpParams params) throws HttpException, IOException {
HttpResponse response = super.receiveResponseHeader(params);
if (HEADERS_LOG.isDebugEnabled()) {
HEADERS_LOG.debug(">> " + response.getStatusLine().toString());
HEADERS_LOG.debug("<< " + response.getStatusLine().toString());
Header[] headers = response.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
HEADERS_LOG.debug(">> " + headers[i].toString());
HEADERS_LOG.debug("<< " + headers[i].toString());
}
}
return response;
@ -217,10 +217,10 @@ public class DefaultClientConnection extends SocketHttpClientConnection
public void sendRequestHeader(HttpRequest request) throws HttpException, IOException {
super.sendRequestHeader(request);
if (HEADERS_LOG.isDebugEnabled()) {
HEADERS_LOG.debug("<< " + request.getRequestLine().toString());
HEADERS_LOG.debug(">> " + request.getRequestLine().toString());
Header[] headers = request.getAllHeaders();
for (int i = 0; i < headers.length; i++) {
HEADERS_LOG.debug("<< " + headers[i].toString());
HEADERS_LOG.debug(">> " + headers[i].toString());
}
}
}