Index: java/org/apache/commons/httpclient/HostConfiguration.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java,v
retrieving revision 1.15
diff -u -r1.15 HostConfiguration.java
--- java/org/apache/commons/httpclient/HostConfiguration.java 18 Apr 2004 23:51:34 -0000 1.15
+++ java/org/apache/commons/httpclient/HostConfiguration.java 2 May 2004 10:43:44 -0000
@@ -73,6 +73,9 @@
/** The local address to use when creating the socket, or null to use the default */
private InetAddress localAddress;
+ /** The HTTP protocol version supported by the host */
+ private HttpVersion version;
+
/**
* Constructor for HostConfiguration.
*/
@@ -88,6 +91,7 @@
this.proxyPort = -1;
this.proxySet = false;
this.localAddress = null;
+ this.version = null;
}
/**
@@ -110,6 +114,7 @@
this.proxyPort = hostConfiguration.getProxyPort();
this.proxySet = hostConfiguration.isProxySet();
this.localAddress = hostConfiguration.getLocalAddress();
+ this.version = hostConfiguration.getVersion();
}
}
@@ -139,6 +144,9 @@
if (virtualHost != null) {
b.append(", virtualHost=").append(virtualHost);
}
+ if (version != null) {
+ b.append(", version=").append(version);
+ }
}
if (isProxySet()) {
if (appendComma) {
@@ -450,6 +458,25 @@
}
/**
+ * Returns the HTTP protocol version supported by the host (may be null if the
+ * HTTP protocol version supported by the host is not known or not specified).
+ *
+ * @return HTTP protocol version
+ */
+ public HttpVersion getVersion() {
+ return this.version;
+ }
+
+ /**
+ * Defines the HTTP protocol version supported by the host (may be null if the
+ * HTTP protocol version supported by the host is not known or not specified)
+ *
+ * @param version HTTP protocol version
+ */
+ public void setVersion(HttpVersion version) {
+ this.version = version;
+ }
+ /**
* @see java.lang.Object#equals(java.lang.Object)
*/
public synchronized boolean equals(Object o) {
@@ -526,4 +553,5 @@
return super.hashCode();
}
}
+
}
Index: java/org/apache/commons/httpclient/HttpMethodBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.204
diff -u -r1.204 HttpMethodBase.java
--- java/org/apache/commons/httpclient/HttpMethodBase.java 18 Apr 2004 23:51:35 -0000 1.204
+++ java/org/apache/commons/httpclient/HttpMethodBase.java 2 May 2004 10:43:50 -0000
@@ -81,7 +81,7 @@
* @author dIon Gillard
* @author Jeff Dever
* @author Davanum Srinivas
- * @author Ortwin Gl�ck
+ * @author Ortwin Glueck
* @author Eric Johnson
* @author Michael Becke
* @author Oleg Kalnichevski
@@ -165,6 +165,9 @@
/** Number of milliseconds to wait for 100-contunue response. */
private static final int RESPONSE_WAIT_TIME_MS = 3000;
+ /** HTTP protocol version used for execution of this method. */
+ private HttpVersion actualVersion = null;
+
// ----------------------------------------------------------- Constructors
/**
@@ -352,7 +355,7 @@
* @deprecated Use {@link HttpMethodParams#getVersion()}
*/
public boolean isHttp11() {
- return getHttpVersion().equals(HttpVersion.HTTP_1_1);
+ return this.params.getVersion().equals(HttpVersion.HTTP_1_1);
}
/**
@@ -886,17 +889,16 @@
}
LOG.debug("Resorting to protocol version default close connection policy");
// missing or invalid connection header, do the default
- HttpVersion version = getHttpVersion();
- if (version.greaterEquals(HttpVersion.HTTP_1_1)) {
+ if (this.actualVersion.greaterEquals(HttpVersion.HTTP_1_1)) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Should NOT close connection, using " + version.toString());
+ LOG.debug("Should NOT close connection, using " + this.actualVersion.toString());
}
} else {
if (LOG.isDebugEnabled()) {
- LOG.debug("Should close connection, using " + version.toString());
+ LOG.debug("Should close connection, using " + this.actualVersion.toString());
}
}
- return version.lessEquals(HttpVersion.HTTP_1_0);
+ return this.actualVersion.lessEquals(HttpVersion.HTTP_1_0);
}
/**
@@ -956,7 +958,11 @@
conn.setLastResponseInputStream(null);
- // TODO: this needs to be exposed
+ // determine the effective protocol version
+ if (this.actualVersion == null) {
+ this.actualVersion = this.params.getVersion();
+ }
+
boolean requestSent = false;
writeRequest(state, conn);
requestSent = true;
@@ -1776,7 +1782,7 @@
statusLine.toString());
}
} else {
- getParams().setVersion(HttpVersion.parse(versionStr));
+ this.actualVersion = HttpVersion.parse(versionStr);
}
}
@@ -1996,7 +2002,7 @@
*/
private String getRequestLine(HttpConnection conn) {
return HttpMethodBase.generateRequestLine(conn, getName(),
- getPath(), getQueryString(), getHttpVersion().toString());
+ getPath(), getQueryString(), this.actualVersion.toString());
}
/**
@@ -2025,14 +2031,17 @@
}
/**
- * Returns the HTTP version to be used with this method.
+ * Returns the HTTP version used with this method.
*
* @return HTTP version.
*
- * @since 2.1
+ * @since 3.0
*/
- protected HttpVersion getHttpVersion() {
- return this.params.getVersion();
+ public HttpVersion getActualVersion() {
+ if (this.actualVersion == null) {
+ throw new IllegalStateException("Effective protocol version not known");
+ }
+ return this.actualVersion;
}
/**
Index: java/org/apache/commons/httpclient/HttpMethodDirector.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodDirector.java,v
retrieving revision 1.22
diff -u -r1.22 HttpMethodDirector.java
--- java/org/apache/commons/httpclient/HttpMethodDirector.java 18 Apr 2004 23:51:35 -0000 1.22
+++ java/org/apache/commons/httpclient/HttpMethodDirector.java 2 May 2004 10:43:53 -0000
@@ -45,6 +45,7 @@
import org.apache.commons.httpclient.auth.HttpAuthRealm;
import org.apache.commons.httpclient.auth.MalformedChallengeException;
import org.apache.commons.httpclient.params.HttpClientParams;
+import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.params.HttpParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -123,6 +124,12 @@
throw new IllegalArgumentException("Method may not be null");
}
method.getParams().setDefaults(this.params);
+
+ // Check if the host is known to implement only a specfic version of HTTP protocol
+ if (this.hostConfiguration.getVersion() != null
+ && !method.getParams().isParameterSetLocally(HttpMethodParams.PROTOCOL_VERSION)) {
+ method.getParams().setVersion(this.hostConfiguration.getVersion());
+ }
try {
int maxRedirects = this.params.getIntParameter(HttpClientParams.MAX_REDIRECTS, 100);
Index: java/org/apache/commons/httpclient/HttpVersion.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpVersion.java,v
retrieving revision 1.3
diff -u -r1.3 HttpVersion.java
--- java/org/apache/commons/httpclient/HttpVersion.java 18 Apr 2004 23:51:35 -0000 1.3
+++ java/org/apache/commons/httpclient/HttpVersion.java 2 May 2004 10:43:53 -0000
@@ -66,7 +66,7 @@
* @version $Revision: 1.3 $ $Date: 2004/04/18 23:51:35 $
*
*/
-public class HttpVersion {
+public class HttpVersion implements Comparable {
/** Major version number of the HTTP protocol */
private int major = 0;
@@ -141,16 +141,39 @@
}
/**
+ * Compares this HTTP protocol version with another one.
+ *
+ * @param anotherVer the version to be compared with.
+ *
+ * @return a negative integer, zero, or a positive integer as this version is less than,
+ * equal to, or greater than the specified version.
+ */
+ public int compareTo(HttpVersion anotherVer) {
+ if (anotherVer == null) {
+ throw new IllegalArgumentException("Version parameter may not be null");
+ }
+ int delta = getMajor() - anotherVer.getMajor();
+ if (delta == 0) {
+ delta = getMinor() - anotherVer.getMinor();
+ }
+ return delta;
+ }
+
+ /**
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object o) {
+ return compareTo((HttpVersion)o);
+ }
+
+ /**
* Test if the HTTP protocol version is equal to the given number.
*
* @return true if HTTP protocol version is given to the given number,
* false otherwise.
*/
public boolean equals(HttpVersion version) {
- if (version == null) {
- throw new IllegalArgumentException("Version parameter may not be null");
- }
- return (getMajor() == version.getMajor() && getMinor() == version.getMinor());
+ return compareTo(version) == 0;
}
/**
@@ -160,14 +183,7 @@
* given number, false otherwise.
*/
public boolean greaterEquals(HttpVersion version) {
- if (version == null) {
- throw new IllegalArgumentException("Version parameter may not be null");
- }
- int delta = getMajor() - version.getMajor();
- if (delta == 0) {
- delta = getMinor() - version.getMinor();
- }
- return delta >= 0;
+ return compareTo(version) >= 0;
}
/**
@@ -177,11 +193,7 @@
* given number, false otherwise.
*/
public boolean lessEquals(HttpVersion version) {
- int delta = getMajor() - version.getMajor();
- if (delta == 0) {
- delta = getMinor() - version.getMinor();
- }
- return delta <= 0;
+ return compareTo(version) <= 0;
}
/**
@@ -231,4 +243,5 @@
}
return new HttpVersion(major, minor);
}
+
}
Index: java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v
retrieving revision 1.32
diff -u -r1.32 EntityEnclosingMethod.java
--- java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 28 Apr 2004 02:23:17 -0000 1.32
+++ java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 2 May 2004 10:43:55 -0000
@@ -355,7 +355,7 @@
if (len >= 0) {
addRequestHeader("Content-Length", String.valueOf(len));
} else if ((len == CONTENT_LENGTH_CHUNKED)
- && (getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1))) {
+ && (getActualVersion().greaterEquals(HttpVersion.HTTP_1_1))) {
addRequestHeader("Transfer-Encoding", "chunked");
}
}
@@ -419,10 +419,10 @@
long contentLength = getRequestContentLength();
if ((contentLength == CONTENT_LENGTH_CHUNKED)
- && getHttpVersion().lessEquals(HttpVersion.HTTP_1_0)) {
+ && getActualVersion().lessEquals(HttpVersion.HTTP_1_0)) {
throw new ProtocolException(
"Chunked transfer encoding not allowed for " +
- getHttpVersion().toString());
+ getActualVersion().toString());
}
this.requestEntity = generateRequestEntity();
Index: java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java,v
retrieving revision 1.12
diff -u -r1.12 ExpectContinueMethod.java
--- java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java 18 Apr 2004 23:51:37 -0000 1.12
+++ java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java 2 May 2004 10:43:56 -0000
@@ -189,7 +189,7 @@
// = request body present
if (getParams().isParameterTrue(HttpMethodParams.USE_EXPECT_CONTINUE)
- && getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1)
+ && getActualVersion().greaterEquals(HttpVersion.HTTP_1_1)
&& hasRequestContent())
{
if (!headerPresent) {
Index: java/org/apache/commons/httpclient/params/DefaultHttpParams.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParams.java,v
retrieving revision 1.6
diff -u -r1.6 DefaultHttpParams.java
--- java/org/apache/commons/httpclient/params/DefaultHttpParams.java 18 Apr 2004 23:51:37 -0000 1.6
+++ java/org/apache/commons/httpclient/params/DefaultHttpParams.java 2 May 2004 10:43:56 -0000
@@ -210,6 +210,14 @@
setParameter(name, new Boolean(value));
}
+ public boolean isParameterSet(final String name) {
+ return getParameter(name) != null;
+ }
+
+ public boolean isParameterSetLocally(final String name) {
+ return this.parameters != null && this.parameters.get(name) != null;
+ }
+
public boolean isParameterTrue(final String name) {
return getBooleanParameter(name, false);
}
Index: java/org/apache/commons/httpclient/params/HttpParams.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpParams.java,v
retrieving revision 1.4
diff -u -r1.4 HttpParams.java
--- java/org/apache/commons/httpclient/params/HttpParams.java 18 Apr 2004 23:51:37 -0000 1.4
+++ java/org/apache/commons/httpclient/params/HttpParams.java 2 May 2004 10:43:57 -0000
@@ -186,6 +186,26 @@
public void setBooleanParameter(final String name, boolean value);
/**
+ * Returns true if the parameter is set at any level, false otherwise.
+ *
+ * @param name parameter name
+ *
+ * @return true if the parameter is set at any level, false
+ * otherwise.
+ */
+ public boolean isParameterSet(final String name);
+
+ /**
+ * Returns true if the parameter is set locally, false otherwise.
+ *
+ * @param name parameter name
+ *
+ * @return true if the parameter is set locally, false
+ * otherwise.
+ */
+ public boolean isParameterSetLocally(final String name);
+
+ /**
* Returns true if the parameter is set and is true, false
* otherwise.
*