• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpVersion.java $
3  * $Revision: 609106 $
4  * $Date: 2008-01-05 01:15:42 -0800 (Sat, 05 Jan 2008) $
5  *
6  * ====================================================================
7  * Licensed to the Apache Software Foundation (ASF) under one
8  * or more contributor license agreements.  See the NOTICE file
9  * distributed with this work for additional information
10  * regarding copyright ownership.  The ASF licenses this file
11  * to you under the Apache License, Version 2.0 (the
12  * "License"); you may not use this file except in compliance
13  * with the License.  You may obtain a copy of the License at
14  *
15  *   http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing,
18  * software distributed under the License is distributed on an
19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20  * KIND, either express or implied.  See the License for the
21  * specific language governing permissions and limitations
22  * under the License.
23  * ====================================================================
24  *
25  * This software consists of voluntary contributions made by many
26  * individuals on behalf of the Apache Software Foundation.  For more
27  * information on the Apache Software Foundation, please see
28  * <http://www.apache.org/>.
29  *
30  */
31 
32 package org.apache.http;
33 
34 import java.io.Serializable;
35 
36 /**
37  * Represents an HTTP version, as specified in RFC 2616.
38  *
39  * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
40  *
41  * @version $Revision: 609106 $ $Date: 2008-01-05 01:15:42 -0800 (Sat, 05 Jan 2008) $
42  */
43 public final class HttpVersion extends ProtocolVersion
44     implements Serializable {
45 
46     private static final long serialVersionUID = -5856653513894415344L;
47 
48     /** The protocol name. */
49     public static final String HTTP = "HTTP";
50 
51     /** HTTP protocol version 0.9 */
52     public static final HttpVersion HTTP_0_9 = new HttpVersion(0, 9);
53 
54     /** HTTP protocol version 1.0 */
55     public static final HttpVersion HTTP_1_0 = new HttpVersion(1, 0);
56 
57     /** HTTP protocol version 1.1 */
58     public static final HttpVersion HTTP_1_1 = new HttpVersion(1, 1);
59 
60 
61     /**
62      * Create an HTTP protocol version designator.
63      *
64      * @param major   the major version number of the HTTP protocol
65      * @param minor   the minor version number of the HTTP protocol
66      *
67      * @throws IllegalArgumentException if either major or minor version number is negative
68      */
HttpVersion(int major, int minor)69     public HttpVersion(int major, int minor) {
70         super(HTTP, major, minor);
71     }
72 
73 
74     /**
75      * Obtains a specific HTTP version.
76      *
77      * @param major     the major version
78      * @param minor     the minor version
79      *
80      * @return  an instance of {@link HttpVersion} with the argument version
81      */
forVersion(int major, int minor)82     public ProtocolVersion forVersion(int major, int minor) {
83 
84         if ((major == this.major) && (minor == this.minor)) {
85             return this;
86         }
87 
88         if (major == 1) {
89             if (minor == 0) {
90                 return HTTP_1_0;
91             }
92             if (minor == 1) {
93                 return HTTP_1_1;
94             }
95         }
96         if ((major == 0) && (minor == 9)) {
97             return HTTP_0_9;
98         }
99 
100         // argument checking is done in the constructor
101         return new HttpVersion(major, minor);
102     }
103 
104 }
105