org.apache.commons.httpclient

Class HttpVersion

Implemented Interfaces:
Comparable<T>

public class HttpVersion
extends Object
implements Comparable<T>

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.

Since:
3.0

Field Summary

static HttpVersion
HTTP_0_9
HTTP protocol version 0.9
static HttpVersion
HTTP_1_0
HTTP protocol version 1.0
static HttpVersion
HTTP_1_1
HTTP protocol version 1.1

Constructor Summary

HttpVersion(int major, int minor)
Create an HTTP protocol version designator.

Method Summary

int
compareTo(Object o)
int
compareTo(HttpVersion anotherVer)
Compares this HTTP protocol version with another one.
boolean
equals(Object obj)
boolean
equals(HttpVersion version)
Test if the HTTP protocol version is equal to the given number.
int
getMajor()
Returns the major version number of the HTTP protocol.
int
getMinor()
Returns the minor version number of the HTTP protocol.
boolean
greaterEquals(HttpVersion version)
Test if the HTTP protocol version is greater or equal to the given number.
int
hashCode()
boolean
lessEquals(HttpVersion version)
Test if the HTTP protocol version is less or equal to the given number.
static HttpVersion
parse(String s)
Parses the textual representation of the given HTTP protocol version.
String
toString()

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

HTTP_0_9

public static final HttpVersion HTTP_0_9
HTTP protocol version 0.9

HTTP_1_0

public static final HttpVersion HTTP_1_0
HTTP protocol version 1.0
Usages and Demos :

View More Examples of HTTP_1_0
   1: import org.apache.commons.httpclient.HttpStatus;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: 
   4:         ...
   5:             response = new SimpleResponse();
   6:             response.setStatusLine(HttpVersion.HTTP_1_0, statusCode);
   7:             response.setHeader(new Header("Content-Type", "text/plain; charset=US-ASCII"));
   8: 
   9:             String s = HttpStatus.getStatusText(statusCode);

View Full Code Here
   1: import org.apache.commons.httpclient.HttpStatus;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.methods.GetMethod;
   4:         ...
   5:             {
   6:                 HttpVersion ver = request.getRequestLine().getHttpVersion();
   7:         ...
   8:                 if (ver.equals(HttpVersion.HTTP_1_0)) {
   9:                     return false;
  10:         ...
  11: 
  12:         this.client.getParams().setVersion(HttpVersion.HTTP_1_1);

View Full Code Here
   1: import org.apache.commons.httpclient.HttpState;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.NTCredentials;
   4:         ...
   5:                 ?
   6:                 HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1);
   7: 
   8: 

View Full Code Here
   1: import org.apache.commons.httpclient.HttpStatus;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.auth.AuthChallengeParser;
   4:         ...
   5: 
   6:         method.getParams().setVersion(HttpVersion.HTTP_1_0);
   7: 
   8:         ...
   9:         hcp.setSoTimeout(timeout);
  10:         hcp.setVersion(HttpVersion.HTTP_1_0);

View Full Code Here

HTTP_1_1

public static final HttpVersion HTTP_1_1
HTTP protocol version 1.1
Usages and Demos :

View More Examples of HTTP_1_1
   1: import org.apache.commons.httpclient.HttpClient;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
   4:         ...
   5:         this.httpClient3FactoryBean.setStrict(false);
   6:         this.httpClient3FactoryBean.setVersion(HttpVersion.HTTP_1_1);
   7:         this.httpClient3FactoryBean.setDefaultMaxConnectionsPerHost(CONST_TIMEOUT);
   8:         ...
   9:         assertEquals(CONST_TIMEOUT, client.getParams().getSoTimeout());
  10:         assertEquals(HttpVersion.HTTP_1_1, client.getParams().getVersion());
  11:         assertEquals(HttpClient.class, this.httpClient3FactoryBean.getObjectType());

View Full Code Here
   1: import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.SimpleHttpConnectionManager;
   4:         ...
   5:         params.setParameter(HttpMethodParams.USER_AGENT, "Jakarta Commons-HttpClient/3.1");
   6:         params.setVersion(HttpVersion.HTTP_1_1);
   7:         params.setConnectionManagerClass(SimpleHttpConnectionManager.class);
   8:         params.setCookiePolicy(CookiePolicy.DEFAULT);
   9:         params.setHttpElementCharset("US-ASCII");

View Full Code Here
   1: import org.apache.commons.httpclient.HttpStatus;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.methods.GetMethod;
   4:         ...
   5:             {
   6:                 HttpVersion ver = request.getRequestLine().getHttpVersion();
   7:         ...
   8:                 if (ver.equals(HttpVersion.HTTP_1_0)) {
   9:                     return false;
  10:         ...
  11: 
  12:         this.client.getParams().setVersion(HttpVersion.HTTP_1_1);

View Full Code Here
   1: import org.apache.commons.httpclient.HttpStatus;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:     
   6:     private HttpVersion ver = HttpVersion.HTTP_1_1;
   7:     private int statuscode = HttpStatus.SC_OK;
   8:         ...
   9:         }
  10:         setStatusLine(HttpVersion.parse(statusline.getHttpVersion()),
  11:                 statusline.getStatusCode(), statusline.getReasonPhrase());

View Full Code Here
   1: 
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.cookie.CookiePolicy;
   4:         ...
   5:     
   6:     public HttpVersion getVersion() { 
   7:         Object param = getParameter(PROTOCOL_VERSION);
   8:         ...
   9:         if (param == null) {
  10:             return HttpVersion.HTTP_1_1;
  11:         }
  12:         ...
  13:         return (HttpVersion)param;

View Full Code Here

Constructor Details

HttpVersion

public HttpVersion(int major,
                   int minor)
Create an HTTP protocol version designator.
Parameters:
major - the major version number of the HTTP protocol
minor - the minor version number of the HTTP protocol
Throws:
IllegalArgumentException - if either major or minor version number is negative
Usages and Demos :

View More Examples of HttpVersion(int major,int minor)
   1: 
   2:         client.getParams().setVersion(new HttpVersion(1, 0));
   3: 
   4:         int statusCode = -1;
   5:         try {

View Full Code Here
   1: 
   2:         client.getParams().setVersion(new HttpVersion(1, 0));
   3: 
   4:         int statusCode = -1;
   5:         try {

View Full Code Here

Method Details

compareTo

public int compareTo(Object o)
See Also:
java.lang.Comparable.compareTo(java.lang.Object)

compareTo

public int compareTo(HttpVersion anotherVer)
Compares this HTTP protocol version with another one.
Parameters:
anotherVer - the version to be compared with.
Returns:
a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the specified version.

equals

public boolean equals(Object obj)
Overrides:
equals in interface Object

equals

public boolean equals(HttpVersion version)
Test if the HTTP protocol version is equal to the given number.
Returns:
true if HTTP protocol version is given to the given number, false otherwise.

getMajor

public int getMajor()
Returns the major version number of the HTTP protocol.
Returns:
the major version number.

getMinor

public int getMinor()
Returns the minor version number of the HTTP protocol.
Returns:
the minor version number.

greaterEquals

public boolean greaterEquals(HttpVersion version)
Test if the HTTP protocol version is greater or equal to the given number.
Returns:
true if HTTP protocol version is greater or equal given to the given number, false otherwise.

hashCode

public int hashCode()
Overrides:
hashCode in interface Object

lessEquals

public boolean lessEquals(HttpVersion version)
Test if the HTTP protocol version is less or equal to the given number.
Returns:
true if HTTP protocol version is less or equal to given to the given number, false otherwise.

parse

public static HttpVersion parse(String s)
            throws ProtocolException
Parses the textual representation of the given HTTP protocol version.
Returns:
HTTP protocol version.
Throws:
ProtocolException - if the string is not a valid HTTP protocol version.
Usages and Demos :

View More Examples of parse(String s)
   1: import org.apache.commons.httpclient.HttpException;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.ProtocolException;
   4:         ...
   5: 
   6:     private HttpVersion httpversion = null;
   7:     private String method = null;
   8:         ...
   9:     throws ProtocolException {
  10:         this(method, uri, HttpVersion.parse(httpversion));
  11:     }

View Full Code Here
   1: import org.apache.commons.httpclient.HttpStatus;
   2: import org.apache.commons.httpclient.HttpVersion;
   3: import org.apache.commons.httpclient.NameValuePair;
   4:         ...
   5:     
   6:     private HttpVersion ver = HttpVersion.HTTP_1_1;
   7:     private int statuscode = HttpStatus.SC_OK;
   8:         ...
   9:         }
  10:         setStatusLine(HttpVersion.parse(statusline.getHttpVersion()),
  11:                 statusline.getStatusCode(), statusline.getReasonPhrase());

View Full Code Here

toString

public String toString()
Overrides:
toString in interface Object