View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.spdy.server.http;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.eclipse.jetty.spdy.api.SPDY;
25  
26  /**
27   * <p>{@link HTTPSPDYHeader} defines the SPDY headers that are not also HTTP headers,
28   * such as <tt>method</tt>, <tt>version</tt>, etc. or that are treated differently
29   * by the SPDY protocol, such as <tt>host</tt>.</p>
30   */
31  public enum HTTPSPDYHeader
32  {
33      METHOD("method", ":method"),
34      URI("url", ":path"),
35      VERSION("version", ":version"),
36      SCHEME("scheme", ":scheme"),
37      HOST("host", ":host"),
38      STATUS("status", ":status");
39  
40      public static HTTPSPDYHeader from(short version, String name)
41      {
42          switch (version)
43          {
44              case SPDY.V2:
45                  return Names.v2Names.get(name);
46              case SPDY.V3:
47                  return Names.v3Names.get(name);
48              default:
49                  throw new IllegalStateException();
50          }
51      }
52  
53      private final String v2Name;
54      private final String v3Name;
55  
56      private HTTPSPDYHeader(String v2Name, String v3Name)
57      {
58          this.v2Name = v2Name;
59          Names.v2Names.put(v2Name, this);
60          this.v3Name = v3Name;
61          Names.v3Names.put(v3Name, this);
62      }
63  
64      public String name(short version)
65      {
66          switch (version)
67          {
68              case SPDY.V2:
69                  return v2Name;
70              case SPDY.V3:
71                  return v3Name;
72              default:
73                  throw new IllegalStateException();
74          }
75      }
76  
77      private static class Names
78      {
79          private static final Map<String, HTTPSPDYHeader> v2Names = new HashMap<>();
80          private static final Map<String, HTTPSPDYHeader> v3Names = new HashMap<>();
81      }
82  }