org.apache.commons.httpclient
public class: HttpVersion [javadoc |
source]
java.lang.Object
org.apache.commons.httpclient.HttpVersion
All Implemented Interfaces:
Comparable
HTTP version, as specified in RFC 2616.
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.
The version of an HTTP message is indicated by an HTTP-Version field
in the first line of the message.
HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
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.
- author:
< - a href="mailto:oleg@ural.ru">Oleg Kalnichevski
- version:
$ - Revision: 480424 $ $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
- since:
3.0 -
| Field Summary |
|---|
| public static final HttpVersion | HTTP_0_9 | HTTP protocol version 0.9 |
| public static final HttpVersion | HTTP_1_0 | HTTP protocol version 1.0 |
| public static final HttpVersion | HTTP_1_1 | HTTP protocol version 1.1 |
| Method from org.apache.commons.httpclient.HttpVersion Summary: |
|---|
|
compareTo, compareTo, equals, equals, getMajor, getMinor, greaterEquals, hashCode, lessEquals, parse, toString |
| Method from org.apache.commons.httpclient.HttpVersion Detail: |
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;
}
Compares this HTTP protocol version with another one. |
public int compareTo(Object o) {
return compareTo((HttpVersion)o);
}
|
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof HttpVersion)) {
return false;
}
return equals((HttpVersion)obj);
}
|
public boolean equals(HttpVersion version) {
return compareTo(version) == 0;
}
Test if the HTTP protocol version is equal to the given number. |
public int getMajor() {
return major;
}
Returns the major version number of the HTTP protocol. |
public int getMinor() {
return minor;
}
Returns the minor version number of the HTTP protocol. |
public boolean greaterEquals(HttpVersion version) {
return compareTo(version) >= 0;
}
Test if the HTTP protocol version is greater or equal to the given number. |
public int hashCode() {
return this.major * 100000 + this.minor;
}
|
public boolean lessEquals(HttpVersion version) {
return compareTo(version) < = 0;
}
Test if the HTTP protocol version is less or equal to the given number. |
public static HttpVersion parse(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);
}
Parses the textual representation of the given HTTP protocol version. |
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("HTTP/");
buffer.append(this.major);
buffer.append('.");
buffer.append(this.minor);
return buffer.toString();
}
|