You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2003/07/30 23:11:17 UTC
cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestHttpVersion.java TestNoHost.java
olegk 2003/07/30 14:11:17
Modified: httpclient/src/java/org/apache/commons/httpclient
HttpMethodBase.java HttpRecoverableException.java
httpclient/src/java/org/apache/commons/httpclient/methods
EntityEnclosingMethod.java
ExpectContinueMethod.java
httpclient/src/test/org/apache/commons/httpclient
TestNoHost.java
Added: httpclient/src/java/org/apache/commons/httpclient
HttpVersion.java
httpclient/src/test/org/apache/commons/httpclient
TestHttpVersion.java
Log:
Bug fix #10791 (HTTP Version configuration and tracking)
Contributed by Oleg Kalnichevski
Reviewed by Michael Becke & Laura Werner
Revision Changes Path
1.174 +52 -30 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
Index: HttpMethodBase.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.173
retrieving revision 1.174
diff -u -r1.173 -r1.174
--- HttpMethodBase.java 25 Jul 2003 18:29:31 -0000 1.173
+++ HttpMethodBase.java 30 Jul 2003 21:11:17 -0000 1.174
@@ -196,8 +196,8 @@
/** Whether or not I should automatically process authentication. */
private boolean doAuthentication = true;
- /** Whether or not I should use the HTTP/1.1 protocol. The default is <tt>true</tt>. */
- private boolean http11 = true;
+ /** Version of the HTTP protocol to be used. */
+ private HttpVersion version = HttpVersion.HTTP_1_1;
/** True if we're in strict mode. The default is <tt>false</tt>. */
private boolean strictMode = false;
@@ -363,9 +363,15 @@
* Set whether or not I should use the HTTP/1.1 protocol.
*
* @param http11 true to use HTTP/1.1, false to use 1.0
+ *
+ * @deprecated Use @{link #setHttpVersion(HttpVersion)}
*/
public void setHttp11(boolean http11) {
- this.http11 = http11;
+ if (http11) {
+ this.version = HttpVersion.HTTP_1_1;
+ } else {
+ this.version = HttpVersion.HTTP_1_0;
+ }
}
/**
@@ -397,9 +403,11 @@
* HTTP/1.1 protocol. The default is <tt>true</tt>.
*
* @return <tt>true</tt> if I should use the HTTP/1.1 protocol
+ *
+ * @deprecated Use {@link #getHttpVersion()}
*/
public boolean isHttp11() {
- return http11;
+ return this.version.equals(HttpVersion.HTTP_1_1);
}
/**
@@ -894,12 +902,16 @@
}
LOG.debug("Resorting to protocol version default close connection policy");
// missing or invalid connection header, do the default
- if (http11) {
- LOG.debug("Should NOT close connection, using HTTP/1.1.");
+ if (this.version.greaterEquals(HttpVersion.HTTP_1_1)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Should NOT close connection, using " + this.version.toString());
+ }
} else {
- LOG.debug("Should close connection, using HTTP/1.0.");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Should close connection, using " + this.version.toString());
+ }
}
- return !http11;
+ return this.version.lessEquals(HttpVersion.HTTP_1_0);
}
/**
@@ -1256,7 +1268,7 @@
getResponseTrailerHeaderGroup().clear();
statusLine = null;
used = false;
- http11 = true;
+ version = HttpVersion.HTTP_1_1;
responseBody = null;
recoverableExceptionCount = 0;
inExecute = false;
@@ -2049,19 +2061,16 @@
statusLine = new StatusLine(statusString);
//check for a valid HTTP-Version
- String httpVersion = statusLine.getHttpVersion();
- if (httpVersion.equals("HTTP/1.0")) {
- http11 = false;
- } else if (httpVersion.equals("HTTP/1.1")) {
- http11 = true;
- } else if (httpVersion.equals("HTTP")) {
- // some servers do not specify the version correctly, we will just assume 1.0
- http11 = false;
+ String versionStr = statusLine.getHttpVersion();
+ if (!this.strictMode && versionStr.equals("HTTP")) {
+ this.version = HttpVersion.HTTP_1_0;
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Ambiguous status line (HTTP protocol version missing):" +
+ statusLine.toString());
+ }
} else {
- throw new ProtocolException("Unrecognized server protocol: '"
- + httpVersion + "'");
+ this.version = HttpVersion.parse(versionStr);
}
-
}
// ------------------------------------------------------ Protected Methods
@@ -2266,18 +2275,31 @@
*/
private String getRequestLine(HttpConnection conn) {
return HttpMethodBase.generateRequestLine(conn, getName(),
- getPath(), getQueryString(), getHttpVersion());
+ getPath(), getQueryString(), getHttpVersion().toString());
}
/**
- * Get the HTTP version.
+ * Get the HTTP version to be used with this method.
*
- * @return HTTP/1.1 if http11, HTTP/1.0 otherwise
+ * @return HTTP version.
*
- * @since 2.0
+ * @since 2.1
*/
- private String getHttpVersion() {
- return (http11 ? "HTTP/1.1" : "HTTP/1.0");
+ public HttpVersion getHttpVersion() {
+ return this.version;
+ }
+
+ /**
+ * Set the HTTP version to be used with this method.
+ *
+ * @since 2.1
+ */
+ public void setHttpVersion(HttpVersion version) {
+ if (version == null) {
+ this.version = HttpVersion.HTTP_1_1;
+ } else {
+ this.version = version;
+ }
}
/**
1.10 +5 -5 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java
Index: HttpRecoverableException.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HttpRecoverableException.java 16 Jul 2003 20:48:27 -0000 1.9
+++ HttpRecoverableException.java 30 Jul 2003 21:11:17 -0000 1.10
@@ -70,7 +70,7 @@
* Signals that an HTTP or HttpClient exception has occurred. This
* exception may have been caused by a transient error and the request
* may be retried. It may be possible to retrieve the underlying transient
- * error via the inherited {@link TransportException#getCause()} method.
+ * error via the inherited {@link HttpException#getCause()} method.
* </p>
* @author Unascribed
* @version $Revision$ $Date$
1.1 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpVersion.java
Index: HttpVersion.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpVersion.java,v 1.1 2003/07/30 21:11:17 olegk Exp $
* $Revision: 1.1 $
* $Date: 2003/07/30 21:11:17 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.commons.httpclient;
/**
* <p>HTTP version, as specified in RFC 2616.</p>
* <p>
* HTTP uses a "<major>.<minor>" numbering scheme to indicate versions
* of the protocol. The protocol versioning policy is intended to allow
* the sender to indicate the format of a message and its capacity for
* understanding further HTTP communication, rather than the features
* obtained via that communication. No change is made to the version
* number for the addition of message components which do not affect
* communication behavior or which only add to extensible field values.
* The <minor> number is incremented when the changes made to the
* protocol add features which do not change the general message parsing
* algorithm, but which may add to the message semantics and imply
* additional capabilities of the sender. The <major> number is
* incremented when the format of a message within the protocol is
* changed. See RFC 2145 [36] for a fuller explanation.
* </p>
* <p>
* The version of an HTTP message is indicated by an HTTP-Version field
* in the first line of the message.
* </p>
* <pre>
* HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
* </pre>
* <p>
* Note that the major and minor numbers MUST be treated as separate
* integers and that each MAY be incremented higher than a single digit.
* Thus, HTTP/2.4 is a lower version than HTTP/2.13, which in turn is
* lower than HTTP/12.3. Leading zeros MUST be ignored by recipients and
* MUST NOT be sent.
* </p>
*
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
*
* @version $Revision: 1.1 $ $Date: 2003/07/30 21:11:17 $
*
*/
public class HttpVersion {
/** Major version number of the HTTP protocol */
private int major = 0;
/** Minor version number of the HTTP protocol */
private int minor = 0;
/** HTTP protocol version 0.9 */
public static final HttpVersion HTTP_0_9 = new HttpVersion(0, 9);
/** HTTP protocol version 1.0 */
public static final HttpVersion HTTP_1_0 = new HttpVersion(1, 0);
/** HTTP protocol version 1.1 */
public static final HttpVersion HTTP_1_1 = new HttpVersion(1, 1);
/**
* Create an HTTP protocol version designator.
*
* @param major the major version number of the HTTP protocol
* @param minor the minor version number of the HTTP protocol
*
* @throws IllegalArgumentException if either major or minor version number is negative
*/
public HttpVersion(int major, int minor) {
if (major < 0) {
throw new IllegalArgumentException("HTTP major version number may not be negative");
}
this.major = major;
if (minor < 0) {
throw new IllegalArgumentException("HTTP minor version number may not be negative");
}
this.minor = minor;
}
/**
* Returns the major version number of the HTTP protocol.
*
* @return the major version number.
*/
public int getMajor() {
return major;
}
/**
* Returns the minor version number of the HTTP protocol.
*
* @return the minor version number.
*/
public int getMinor() {
return minor;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return this.major * 100000 + this.minor;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof HttpVersion)) {
return false;
}
return equals((HttpVersion)obj);
}
/**
* Test if the HTTP protocol version is equal to the given number.
*
* @return <tt>true</tt> if HTTP protocol version is given to the given number,
* <tt>false</tt> 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());
}
/**
* Test if the HTTP protocol version is greater or equal to the given number.
*
* @return <tt>true</tt> if HTTP protocol version is greater or equal given to the
* given number, <tt>false</tt> 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;
}
/**
* Test if the HTTP protocol version is less or equal to the given number.
*
* @return <tt>true</tt> if HTTP protocol version is less or equal to given to the
* given number, <tt>false</tt> otherwise.
*/
public boolean lessEquals(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() {
StringBuffer buffer = new StringBuffer();
buffer.append("HTTP/");
buffer.append(this.major);
buffer.append('.');
buffer.append(this.minor);
return buffer.toString();
}
/**
* Parses the textual representation of the given HTTP protocol version.
*
* @return HTTP protocol version.
*
* @throws ProtocolException if the string is not a valid HTTP protocol version.
*/
public static HttpVersion parse(final String s) throws ProtocolException {
if (s == null) {
throw new IllegalArgumentException("String may not be null");
}
if (!s.startsWith("HTTP/")) {
throw new ProtocolException("Invalid HTTP version string: " + s);
}
int major, minor;
int i1 = "HTTP/".length();
int i2 = s.indexOf(".", i1);
if (i2 == -1) {
throw new ProtocolException("Invalid HTTP version number: " + s);
}
try {
major = Integer.parseInt(s.substring(i1, i2));
} catch (NumberFormatException e) {
throw new ProtocolException("Invalid HTTP major version number: " + s);
}
i1 = i2 + 1;
i2 = s.length();
try {
minor = Integer.parseInt(s.substring(i1, i2));
} catch (NumberFormatException e) {
throw new ProtocolException("Invalid HTTP minor version number: " + s);
}
return new HttpVersion(major, minor);
}
}
1.25 +11 -7 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java
Index: EntityEnclosingMethod.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- EntityEnclosingMethod.java 25 Jul 2003 18:29:32 -0000 1.24
+++ EntityEnclosingMethod.java 30 Jul 2003 21:11:17 -0000 1.25
@@ -74,6 +74,7 @@
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpConstants;
import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.ProtocolException;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.logging.Log;
@@ -367,7 +368,8 @@
long len = getRequestContentLength();
if (len >= 0) {
addRequestHeader("Content-Length", String.valueOf(len));
- } else if ((len == CONTENT_LENGTH_CHUNKED) && (isHttp11())) {
+ } else if ((len == CONTENT_LENGTH_CHUNKED)
+ && (getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1))) {
addRequestHeader("Transfer-Encoding", "chunked");
}
}
@@ -461,9 +463,11 @@
long contentLength = getRequestContentLength();
- if ((contentLength == CONTENT_LENGTH_CHUNKED) && !isHttp11()) {
+ if ((contentLength == CONTENT_LENGTH_CHUNKED)
+ && getHttpVersion().lessEquals(HttpVersion.HTTP_1_0)) {
throw new ProtocolException(
- "Chunked transfer encoding not allowed for HTTP/1.0");
+ "Chunked transfer encoding not allowed for " +
+ getHttpVersion().toString());
}
InputStream instream = null;
1.8 +8 -4 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java
Index: ExpectContinueMethod.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/ExpectContinueMethod.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ExpectContinueMethod.java 26 Jul 2003 10:05:31 -0000 1.7
+++ ExpectContinueMethod.java 30 Jul 2003 21:11:17 -0000 1.8
@@ -68,6 +68,7 @@
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -210,7 +211,10 @@
// = HTTP/1.1 or higher
// = request body present
- if (getUseExpectHeader() && isHttp11() && hasRequestContent()) {
+ if (getUseExpectHeader()
+ && getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1)
+ && hasRequestContent())
+ {
if (!headerPresent) {
setRequestHeader("Expect", "100-continue");
}
1.24 +5 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java
Index: TestNoHost.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- TestNoHost.java 13 Jul 2003 13:54:51 -0000 1.23
+++ TestNoHost.java 30 Jul 2003 21:11:17 -0000 1.24
@@ -105,6 +105,7 @@
suite.addTest(TestRequestLine.suite());
suite.addTest(TestPartsNoHost.suite());
suite.addTest(TestMethodCharEncoding.suite());
+ suite.addTest(TestHttpVersion.suite());
return suite;
}
1.1 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpVersion.java
Index: TestHttpVersion.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpVersion.java,v 1.1 2003/07/30 21:11:17 olegk Exp $
* $Revision: 1.1 $
* $Date: 2003/07/30 21:11:17 $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* 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
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.commons.httpclient;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Test cases for HTTP version class
*
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
*
* @version $Revision: 1.1 $
*/
public class TestHttpVersion extends TestCase {
// ------------------------------------------------------------ Constructor
public TestHttpVersion(String name) {
super(name);
}
// ------------------------------------------------------- TestCase Methods
public static Test suite() {
return new TestSuite(TestHttpVersion.class);
}
// ------------------------------------------------------------------ Tests
public void testHttpVersionParsing() throws Exception {
String s = "HTTP/1.1";
HttpVersion version = HttpVersion.parse(s);
assertEquals("HTTP major version number", 1, version.getMajor());
assertEquals("HTTP minor version number", 1, version.getMinor());
assertEquals("HTTP version number", s, version.toString());
s = "HTTP/123.4567";
version = HttpVersion.parse(s);
assertEquals("HTTP major version number", 123, version.getMajor());
assertEquals("HTTP minor version number", 4567, version.getMinor());
assertEquals("HTTP version number", s, version.toString());
}
public void testInvalidHttpVersionParsing() throws Exception {
try {
HttpVersion.parse("crap");
fail("ProtocolException should have been thrown");
} catch (ProtocolException e) {
//expected
}
try {
HttpVersion.parse("HTTP/crap");
fail("ProtocolException should have been thrown");
} catch (ProtocolException e) {
//expected
}
try {
HttpVersion.parse("HTTP/1");
fail("ProtocolException should have been thrown");
} catch (ProtocolException e) {
//expected
}
try {
HttpVersion.parse("HTTP/1234 ");
fail("ProtocolException should have been thrown");
} catch (ProtocolException e) {
//expected
}
try {
HttpVersion.parse("HTTP/1.");
fail("ProtocolException should have been thrown");
} catch (ProtocolException e) {
//expected
}
try {
HttpVersion.parse("HTTP/1.1 crap");
fail("ProtocolException should have been thrown");
} catch (ProtocolException e) {
//expected
}
}
public void testHttpVersionComparison() {
assertTrue((new HttpVersion(0, 9)).equals(HttpVersion.HTTP_0_9));
assertTrue((new HttpVersion(1, 0)).equals(HttpVersion.HTTP_1_0));
assertTrue((new HttpVersion(1, 1)).equals(HttpVersion.HTTP_1_1));
assertFalse((new HttpVersion(1, 1)).equals(HttpVersion.HTTP_1_0));
assertTrue(HttpVersion.HTTP_0_9.lessEquals(HttpVersion.HTTP_1_1));
assertTrue(HttpVersion.HTTP_0_9.greaterEquals(HttpVersion.HTTP_0_9));
assertFalse(HttpVersion.HTTP_0_9.greaterEquals(HttpVersion.HTTP_1_0));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org