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 29 Apr 2004 17:08:49 -0000 @@ -38,6 +38,7 @@ import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.cookie.CookieSpec; import org.apache.commons.httpclient.cookie.MalformedCookieException; +import org.apache.commons.httpclient.params.HttpConnectionParams; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.util.EncodingUtil; @@ -165,6 +166,9 @@ /** Number of milliseconds to wait for 100-contunue response. */ private static final int RESPONSE_WAIT_TIME_MS = 3000; + /** HTTP protocol version to be used for execution of this method. */ + private HttpVersion effectiveVersion = null; + // ----------------------------------------------------------- Constructors /** @@ -352,7 +356,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 +890,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.effectiveVersion.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.effectiveVersion.toString()); } } else { if (LOG.isDebugEnabled()) { - LOG.debug("Should close connection, using " + version.toString()); + LOG.debug("Should close connection, using " + this.effectiveVersion.toString()); } } - return version.lessEquals(HttpVersion.HTTP_1_0); + return this.effectiveVersion.lessEquals(HttpVersion.HTTP_1_0); } /** @@ -956,7 +959,15 @@ conn.setLastResponseInputStream(null); - // TODO: this needs to be exposed + // determine the effective protocol version + HttpVersion requestedVersion = this.params.getVersion(); + HttpVersion supportedVersion = conn.getParams().getVersion(); + if (requestedVersion.greater(supportedVersion)) { + this.effectiveVersion = supportedVersion; + } else { + this.effectiveVersion = requestedVersion; + } + boolean requestSent = false; writeRequest(state, conn); requestSent = true; @@ -1776,7 +1787,12 @@ statusLine.toString()); } } else { - getParams().setVersion(HttpVersion.parse(versionStr)); + HttpVersion currentVersion = HttpVersion.parse(versionStr); + if (!conn.getParams().isParameterSetLocally(HttpConnectionParams.PROTOCOL_VERSION) || + (currentVersion.greater(conn.getParams().getVersion()))) + { + conn.getParams().setVersion(currentVersion); + } } } @@ -1996,7 +2012,7 @@ */ private String getRequestLine(HttpConnection conn) { return HttpMethodBase.generateRequestLine(conn, getName(), - getPath(), getQueryString(), getHttpVersion().toString()); + getPath(), getQueryString(), this.effectiveVersion.toString()); } /** @@ -2031,8 +2047,11 @@ * * @since 2.1 */ - protected HttpVersion getHttpVersion() { - return this.params.getVersion(); + protected HttpVersion getEffectiveVersion() { + if (this.effectiveVersion == null) { + throw new IllegalStateException("Effective protocol version not known"); + } + return this.effectiveVersion; } /** 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 29 Apr 2004 17:08:50 -0000 @@ -185,6 +185,37 @@ } /** + * Test if the HTTP protocol version is greater than the given number. + * + * @return true if HTTP protocol version is greater than the + * given number, false otherwise. + */ + public boolean greater(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; + } + + /** + * Test if the HTTP protocol version is less othan the given number. + * + * @return true if HTTP protocol version is less than the + * given number, false otherwise. + */ + public boolean less(HttpVersion version) { + int delta = getMajor() - version.getMajor(); + if (delta == 0) { + delta = getMinor() - version.getMinor(); + } + return delta < 0; + } + + /** * @see java.lang.Object#toString() */ public String toString() { 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 29 Apr 2004 17:08:52 -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))) { + && (getEffectiveVersion().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)) { + && getEffectiveVersion().lessEquals(HttpVersion.HTTP_1_0)) { throw new ProtocolException( "Chunked transfer encoding not allowed for " + - getHttpVersion().toString()); + getEffectiveVersion().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 29 Apr 2004 17:08:52 -0000 @@ -189,7 +189,7 @@ // = request body present if (getParams().isParameterTrue(HttpMethodParams.USE_EXPECT_CONTINUE) - && getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1) + && getEffectiveVersion().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 29 Apr 2004 17:08:53 -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/HttpConnectionParams.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpConnectionParams.java,v retrieving revision 1.3 diff -u -r1.3 HttpConnectionParams.java --- java/org/apache/commons/httpclient/params/HttpConnectionParams.java 18 Apr 2004 23:51:37 -0000 1.3 +++ java/org/apache/commons/httpclient/params/HttpConnectionParams.java 29 Apr 2004 17:08:54 -0000 @@ -29,6 +29,8 @@ package org.apache.commons.httpclient.params; +import org.apache.commons.httpclient.HttpVersion; + /** * This class represents a collection of HTTP protocol parameters applicable to * {@link org.apache.commons.httpclient.HttpConnection HTTP connections}. @@ -111,6 +113,15 @@ public static final String STALE_CONNECTION_CHECK = "http.connection.stalecheck"; /** + * Defines the {@link HttpVersion HTTP protocol version} used by + * {@link org.apache.commons.httpclient.HttpConnection HTTP connection}. + *
+ * This parameter expects a value of type {@link HttpVersion}. + *
+ */ + public static final String PROTOCOL_VERSION = "http.protocol.version"; + + /** * Creates a new collection of parameters with the collection returned * by {@link #getDefaultParams()} as a parent. The collection will defer * to its parent for a default value if a particular parameter is not @@ -261,4 +272,32 @@ public void setStaleCheckingEnabled(boolean value) { setBooleanParameter(STALE_CONNECTION_CHECK, value); } + + + /** + * Returns {@link HttpVersion HTTP protocol version} used by the + * {@link org.apache.commons.httpclient.HttpConnection HTTP connection} that + * this collection of parameters applies to. + * + * @return {@link HttpVersion HTTP protocol version} + */ + public HttpVersion getVersion() { + Object param = getParameter(PROTOCOL_VERSION); + if (param == null) { + return HttpVersion.HTTP_1_1; + } + return (HttpVersion)param; + } + + /** + * Assigns the {@link HttpVersion HTTP protocol version} used by the + * {@link org.apache.commons.httpclient.HttpConnection HTTP connection} + * that this collection of parameters applies to. + * + * @param version the {@link HttpVersion HTTP protocol version} + */ + public void setVersion(HttpVersion version) { + setParameter(PROTOCOL_VERSION, version); + } + } 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 29 Apr 2004 17:08:55 -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. *