1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.http;
20
21 import java.nio.ByteBuffer;
22 import java.util.EnumSet;
23
24 import org.eclipse.jetty.util.ArrayTrie;
25 import org.eclipse.jetty.util.BufferUtil;
26 import org.eclipse.jetty.util.Trie;
27
28
29
30
31
32 public enum HttpHeaderValue
33 {
34 CLOSE("close"),
35 CHUNKED("chunked"),
36 GZIP("gzip"),
37 IDENTITY("identity"),
38 KEEP_ALIVE("keep-alive"),
39 CONTINUE("100-continue"),
40 PROCESSING("102-processing"),
41 TE("TE"),
42 BYTES("bytes"),
43 NO_CACHE("no-cache"),
44 UPGRADE("Upgrade"),
45 UNKNOWN("::UNKNOWN::");
46
47
48 public final static Trie<HttpHeaderValue> CACHE= new ArrayTrie<HttpHeaderValue>();
49 static
50 {
51 for (HttpHeaderValue value : HttpHeaderValue.values())
52 if (value!=UNKNOWN)
53 CACHE.put(value.toString(),value);
54 }
55
56 private final String _string;
57 private final ByteBuffer _buffer;
58
59
60 HttpHeaderValue(String s)
61 {
62 _string=s;
63 _buffer=BufferUtil.toBuffer(s);
64 }
65
66
67 public ByteBuffer toBuffer()
68 {
69 return _buffer.asReadOnlyBuffer();
70 }
71
72
73 public boolean is(String s)
74 {
75 return _string.equalsIgnoreCase(s);
76 }
77
78
79 public String asString()
80 {
81 return _string;
82 }
83
84
85 @Override
86 public String toString()
87 {
88 return _string;
89 }
90
91
92 private static EnumSet<HttpHeader> __known =
93 EnumSet.of(HttpHeader.CONNECTION,
94 HttpHeader.TRANSFER_ENCODING,
95 HttpHeader.CONTENT_ENCODING);
96
97
98 public static boolean hasKnownValues(HttpHeader header)
99 {
100 if (header==null)
101 return false;
102 return __known.contains(header);
103 }
104 }