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
23 import org.eclipse.jetty.util.ArrayTrie;
24 import org.eclipse.jetty.util.StringUtil;
25 import org.eclipse.jetty.util.Trie;
26
27
28 public enum HttpHeader
29 {
30
31
32
33 CONNECTION("Connection"),
34 CACHE_CONTROL("Cache-Control"),
35 DATE("Date"),
36 PRAGMA("Pragma"),
37 PROXY_CONNECTION ("Proxy-Connection"),
38 TRAILER("Trailer"),
39 TRANSFER_ENCODING("Transfer-Encoding"),
40 UPGRADE("Upgrade"),
41 VIA("Via"),
42 WARNING("Warning"),
43 NEGOTIATE("Negotiate"),
44
45
46
47
48 ALLOW("Allow"),
49 CONTENT_ENCODING("Content-Encoding"),
50 CONTENT_LANGUAGE("Content-Language"),
51 CONTENT_LENGTH("Content-Length"),
52 CONTENT_LOCATION("Content-Location"),
53 CONTENT_MD5("Content-MD5"),
54 CONTENT_RANGE("Content-Range"),
55 CONTENT_TYPE("Content-Type"),
56 EXPIRES("Expires"),
57 LAST_MODIFIED("Last-Modified"),
58
59
60
61
62 ACCEPT("Accept"),
63 ACCEPT_CHARSET("Accept-Charset"),
64 ACCEPT_ENCODING("Accept-Encoding"),
65 ACCEPT_LANGUAGE("Accept-Language"),
66 AUTHORIZATION("Authorization"),
67 EXPECT("Expect"),
68 FORWARDED("Forwarded"),
69 FROM("From"),
70 HOST("Host"),
71 IF_MATCH("If-Match"),
72 IF_MODIFIED_SINCE("If-Modified-Since"),
73 IF_NONE_MATCH("If-None-Match"),
74 IF_RANGE("If-Range"),
75 IF_UNMODIFIED_SINCE("If-Unmodified-Since"),
76 KEEP_ALIVE("Keep-Alive"),
77 MAX_FORWARDS("Max-Forwards"),
78 PROXY_AUTHORIZATION("Proxy-Authorization"),
79 RANGE("Range"),
80 REQUEST_RANGE("Request-Range"),
81 REFERER("Referer"),
82 TE("TE"),
83 USER_AGENT("User-Agent"),
84 X_FORWARDED_FOR("X-Forwarded-For"),
85 X_FORWARDED_PROTO("X-Forwarded-Proto"),
86 X_FORWARDED_SERVER("X-Forwarded-Server"),
87 X_FORWARDED_HOST("X-Forwarded-Host"),
88
89
90
91
92 ACCEPT_RANGES("Accept-Ranges"),
93 AGE("Age"),
94 ETAG("ETag"),
95 LOCATION("Location"),
96 PROXY_AUTHENTICATE("Proxy-Authenticate"),
97 RETRY_AFTER("Retry-After"),
98 SERVER("Server"),
99 SERVLET_ENGINE("Servlet-Engine"),
100 VARY("Vary"),
101 WWW_AUTHENTICATE("WWW-Authenticate"),
102
103
104
105
106 COOKIE("Cookie"),
107 SET_COOKIE("Set-Cookie"),
108 SET_COOKIE2("Set-Cookie2"),
109 MIME_VERSION("MIME-Version"),
110 IDENTITY("identity"),
111
112 X_POWERED_BY("X-Powered-By"),
113 HTTP2_SETTINGS("HTTP2-Settings"),
114
115 STRICT_TRANSPORT_SECURITY("Strict-Transport-Security"),
116
117
118
119
120 C_METHOD(":method"),
121 C_SCHEME(":scheme"),
122 C_AUTHORITY(":authority"),
123 C_PATH(":path"),
124 C_STATUS(":status"),
125
126 UNKNOWN("::UNKNOWN::");
127
128
129
130 public final static Trie<HttpHeader> CACHE= new ArrayTrie<>(560);
131 static
132 {
133 for (HttpHeader header : HttpHeader.values())
134 if (header!=UNKNOWN)
135 if (!CACHE.put(header.toString(),header))
136 throw new IllegalStateException();
137 }
138
139 private final String _string;
140 private final byte[] _bytes;
141 private final byte[] _bytesColonSpace;
142 private final ByteBuffer _buffer;
143
144
145 HttpHeader(String s)
146 {
147 _string=s;
148 _bytes=StringUtil.getBytes(s);
149 _bytesColonSpace=StringUtil.getBytes(s+": ");
150 _buffer=ByteBuffer.wrap(_bytes);
151 }
152
153
154 public ByteBuffer toBuffer()
155 {
156 return _buffer.asReadOnlyBuffer();
157 }
158
159
160 public byte[] getBytes()
161 {
162 return _bytes;
163 }
164
165
166 public byte[] getBytesColonSpace()
167 {
168 return _bytesColonSpace;
169 }
170
171
172 public boolean is(String s)
173 {
174 return _string.equalsIgnoreCase(s);
175 }
176
177
178 public String asString()
179 {
180 return _string;
181 }
182
183
184 @Override
185 public String toString()
186 {
187 return _string;
188 }
189
190 }
191