View Javadoc
1   /*
2    * Copyright 2015 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.http;
17  
18  import io.netty.util.AsciiString;
19  
20  /**
21   * Defines the common schemes used for the HTTP protocol as defined by
22   * <a href="https://tools.ietf.org/html/rfc7230">rfc7230</a>.
23   */
24  public final class HttpScheme {
25  
26      /**
27       * Scheme for non-secure HTTP connection.
28       */
29      public static final HttpScheme HTTP = new HttpScheme(80, "http");
30  
31      /**
32       * Scheme for secure HTTP connection.
33       */
34      public static final HttpScheme HTTPS = new HttpScheme(443, "https");
35  
36      private final int port;
37      private final AsciiString name;
38  
39      private HttpScheme(int port, String name) {
40          this.port = port;
41          this.name = AsciiString.cached(name);
42      }
43  
44      public AsciiString name() {
45          return name;
46      }
47  
48      public int port() {
49          return port;
50      }
51  
52      @Override
53      public boolean equals(Object o) {
54          if (!(o instanceof HttpScheme)) {
55              return false;
56          }
57          HttpScheme other = (HttpScheme) o;
58          return other.port() == port && other.name().equals(name);
59      }
60  
61      @Override
62      public int hashCode() {
63          return port * 31 + name.hashCode();
64      }
65  
66      @Override
67      public String toString() {
68          return name.toString();
69      }
70  }