1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 }