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  
20  package org.eclipse.jetty.spdy.http;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.eclipse.jetty.spdy.api.SPDY;
26  
27  public enum HTTPSPDYHeader
28  {
29      METHOD("method", ":method"),
30      URI("url", ":path"),
31      VERSION("version", ":version"),
32      SCHEME("scheme", ":scheme"),
33      HOST("host", ":host"),
34      STATUS("status", ":status");
35  
36      public static HTTPSPDYHeader from(short version, String name)
37      {
38          switch (version)
39          {
40              case SPDY.V2:
41                  return Names.v2Names.get(name);
42              case SPDY.V3:
43                  return Names.v3Names.get(name);
44              default:
45                  throw new IllegalStateException();
46          }
47      }
48  
49      private final String v2Name;
50      private final String v3Name;
51  
52      private HTTPSPDYHeader(String v2Name, String v3Name)
53      {
54          this.v2Name = v2Name;
55          Names.v2Names.put(v2Name, this);
56          this.v3Name = v3Name;
57          Names.v3Names.put(v3Name, this);
58      }
59  
60      public String name(short version)
61      {
62          switch (version)
63          {
64              case SPDY.V2:
65                  return v2Name;
66              case SPDY.V3:
67                  return v3Name;
68              default:
69                  throw new IllegalStateException();
70          }
71      }
72  
73      private static class Names
74      {
75          private static final Map<String, HTTPSPDYHeader> v2Names = new HashMap<>();
76          private static final Map<String, HTTPSPDYHeader> v3Names = new HashMap<>();
77      }
78  }