Index: src/java/org/apache/commons/httpclient/ConnectMethod.java
===================================================================
--- src/java/org/apache/commons/httpclient/ConnectMethod.java (revision 312580)
+++ src/java/org/apache/commons/httpclient/ConnectMethod.java (working copy)
@@ -49,13 +49,18 @@
/** the name of this method */
public static final String NAME = "CONNECT";
+ private final HostConfiguration targethost;
+
/**
+ * @deprecated use #ConnectMethod(HttpHost);
+ *
* Create a connect method.
*
* @since 3.0
*/
public ConnectMethod() {
- LOG.trace("enter ConnectMethod()");
+ super();
+ this.targethost = null;
}
/**
@@ -67,10 +72,24 @@
* to the server
*/
public ConnectMethod(HttpMethod method) {
- LOG.trace("enter ConnectMethod(HttpMethod)");
+ super();
+ this.targethost = null;
}
/**
+ * Create a connect method.
+ *
+ * @since 3.0
+ */
+ public ConnectMethod(final HostConfiguration targethost) {
+ super();
+ if (targethost == null) {
+ throw new IllegalArgumentException("Target host may not be null");
+ }
+ this.targethost = targethost;
+ }
+
+ /**
* Provide the {@link #NAME name} of this method.
*
* @return the String "CONNECT"
@@ -78,7 +97,27 @@
public String getName() {
return NAME;
}
+
+ public String getPath() {
+ if (this.targethost != null) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(this.targethost.getHost());
+ int port = this.targethost.getPort();
+ if (port == -1) {
+ port = this.targethost.getProtocol().getDefaultPort();
+ }
+ buffer.append(':');
+ buffer.append(port);
+ return buffer.toString();
+ } else {
+ return "/";
+ }
+ }
+ public URI getURI() throws URIException {
+ return new URI(getPath(), true);
+ }
+
/**
* This method does nothing. CONNECT request is not supposed
* to contain Cookie request header.
@@ -158,15 +197,17 @@
*/
protected void writeRequestLine(HttpState state, HttpConnection conn)
throws IOException, HttpException {
- int port = conn.getPort();
- if (port == -1) {
- port = conn.getProtocol().getDefaultPort();
- }
StringBuffer buffer = new StringBuffer();
buffer.append(getName());
buffer.append(' ');
- buffer.append(conn.getHost());
- if (port > -1) {
+ if (this.targethost != null) {
+ buffer.append(getPath());
+ } else {
+ int port = conn.getPort();
+ if (port == -1) {
+ port = conn.getProtocol().getDefaultPort();
+ }
+ buffer.append(conn.getHost());
buffer.append(':');
buffer.append(port);
}
Index: src/java/org/apache/commons/httpclient/HttpMethodDirector.java
===================================================================
--- src/java/org/apache/commons/httpclient/HttpMethodDirector.java (revision 312580)
+++ src/java/org/apache/commons/httpclient/HttpMethodDirector.java (working copy)
@@ -470,7 +470,7 @@
private boolean executeConnect()
throws IOException, HttpException {
- this.connectMethod = new ConnectMethod();
+ this.connectMethod = new ConnectMethod(this.hostConfiguration);
this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams());
int code;
Index: src/java/org/apache/commons/httpclient/ProxyClient.java
===================================================================
--- src/java/org/apache/commons/httpclient/ProxyClient.java (revision 312580)
+++ src/java/org/apache/commons/httpclient/ProxyClient.java (working copy)
@@ -186,7 +186,7 @@
throw new IllegalStateException("destination host must be configured");
}
- ConnectMethod method = new ConnectMethod();
+ ConnectMethod method = new ConnectMethod(getHostConfiguration());
method.getParams().setDefaults(getParams());
DummyConnectionManager connectionManager = new DummyConnectionManager();