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 3 May 2004 14:05:13 -0000
@@ -29,6 +29,7 @@
package org.apache.commons.httpclient;
+import org.apache.commons.httpclient.params.HostParams;
import org.apache.commons.httpclient.protocol.Protocol;
import java.net.InetAddress;
@@ -73,6 +74,9 @@
/** The local address to use when creating the socket, or null to use the default */
private InetAddress localAddress;
+ /** Parameters specific to this host */
+ private HostParams params;
+
/**
* Constructor for HostConfiguration.
*/
@@ -88,6 +92,7 @@
this.proxyPort = -1;
this.proxySet = false;
this.localAddress = null;
+ this.params = new HostParams();
}
/**
@@ -110,6 +115,11 @@
this.proxyPort = hostConfiguration.getProxyPort();
this.proxySet = hostConfiguration.isProxySet();
this.localAddress = hostConfiguration.getLocalAddress();
+ try {
+ this.params = (HostParams)hostConfiguration.getParams().clone();
+ } catch (CloneNotSupportedException e) {
+ this.params = new HostParams();
+ }
}
}
@@ -450,6 +460,31 @@
}
/**
+ * Returns {@link HostParams HTTP protocol parameters} associated with this host.
+ *
+ * @return HTTP parameters.
+ *
+ * @since 2.1
+ */
+ public HostParams getParams() {
+ return this.params;
+ }
+
+ /**
+ * Assigns {@link HostParams HTTP protocol parameters} specific to this host.
+ *
+ * @since 2.1
+ *
+ * @see HttpMethodParams
+ */
+ public void setParams(final HostParams params) {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
+ this.params = params;
+ }
+
+ /**
* @see java.lang.Object#equals(java.lang.Object)
*/
public synchronized boolean equals(Object o) {
@@ -526,4 +561,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 3 May 2004 14:05:14 -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 effectiveVersion = 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.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 +958,11 @@
conn.setLastResponseInputStream(null);
- // TODO: this needs to be exposed
+ // determine the effective protocol version
+ if (this.effectiveVersion == null) {
+ this.effectiveVersion = this.params.getVersion();
+ }
+
boolean requestSent = false;
writeRequest(state, conn);
requestSent = true;
@@ -1776,7 +1782,7 @@
statusLine.toString());
}
} else {
- getParams().setVersion(HttpVersion.parse(versionStr));
+ this.effectiveVersion = HttpVersion.parse(versionStr);
}
}
@@ -1996,7 +2002,7 @@
*/
private String getRequestLine(HttpConnection conn) {
return HttpMethodBase.generateRequestLine(conn, getName(),
- getPath(), getQueryString(), getHttpVersion().toString());
+ getPath(), getQueryString(), this.effectiveVersion.toString());
}
/**
@@ -2025,14 +2031,15 @@
}
/**
- * Returns the HTTP version to be used with this method.
+ * Returns the HTTP version used with this method (may be null
+ * if undefined, that is, the method has not been executed)
*
* @return HTTP version.
*
- * @since 2.1
+ * @since 3.0
*/
- protected HttpVersion getHttpVersion() {
- return this.params.getVersion();
+ public HttpVersion getEffectiveVersion() {
+ return this.effectiveVersion;
}
/**
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 3 May 2004 14:05:14 -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;
@@ -122,7 +123,10 @@
if (method == null) {
throw new IllegalArgumentException("Method may not be null");
}
- method.getParams().setDefaults(this.params);
+ // Link all parameter collections to form the hierarchy:
+ // Global -> HttpClient -> HostConfiguration -> HttpMethod
+ this.hostConfiguration.getParams().setDefaults(this.params);
+ method.getParams().setDefaults(this.hostConfiguration.getParams());
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 3 May 2004 14:05:14 -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 3 May 2004 14:05:14 -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 3 May 2004 14:05:14 -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 3 May 2004 14:05:14 -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/HostParams.java
===================================================================
RCS file: java/org/apache/commons/httpclient/params/HostParams.java
diff -N java/org/apache/commons/httpclient/params/HostParams.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ java/org/apache/commons/httpclient/params/HostParams.java 3 May 2004 14:05:14 -0000
@@ -0,0 +1,77 @@
+/*
+ * $Header$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+
+package org.apache.commons.httpclient.params;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This class represents a collection of HTTP protocol parameters applicable to
+ * {@link org.apache.commons.httpclient.HostConfiguration instances of HostConfiguration}.
+ * Protocol parameters may be linked together to form a hierarchy. If a particular
+ * parameter value has not been explicitly defined in the collection itself, its
+ * value will be drawn from the parent collection of parameters.
+ *
+ * @author Oleg Kalnichevski
+ *
+ * @version $Revision$
+ */
+public class HostParams extends HttpMethodParams {
+
+ /** Log object for this class. */
+ private static final Log LOG = LogFactory.getLog(HttpParams.class);
+
+ /**
+ * 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
+ * explicitly set in the collection itself.
+ *
+ * @see #getDefaultParams()
+ */
+ public HostParams() {
+ super();
+ }
+
+ /**
+ * Creates a new collection of parameters with the given parent.
+ * The collection will defer to its parent for a default value
+ * if a particular parameter is not explicitly set in the collection
+ * itself.
+ *
+ * @param defaults the parent collection to defer to, if a parameter
+ * is not explictly set in the collection itself.
+ *
+ * @see #getDefaultParams()
+ */
+ public HostParams(HttpParams defaults) {
+ super(defaults);
+ }
+}
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 3 May 2004 14:05:14 -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.
*