2 // ========================================================================
3 // Copyright (c) 1995-2014 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.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.http;
21 import java.nio.ByteBuffer;
23 import org.eclipse.jetty.util.ArrayTrie;
24 import org.eclipse.jetty.util.StringUtil;
25 import org.eclipse.jetty.util.Trie;
28 public enum HttpHeader
30 /* ------------------------------------------------------------ */
33 CONNECTION("Connection"),
34 CACHE_CONTROL("Cache-Control"),
37 PROXY_CONNECTION ("Proxy-Connection"),
39 TRANSFER_ENCODING("Transfer-Encoding"),
43 NEGOTIATE("Negotiate"),
45 /* ------------------------------------------------------------ */
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"),
57 LAST_MODIFIED("Last-Modified"),
59 /* ------------------------------------------------------------ */
63 ACCEPT_CHARSET("Accept-Charset"),
64 ACCEPT_ENCODING("Accept-Encoding"),
65 ACCEPT_LANGUAGE("Accept-Language"),
66 AUTHORIZATION("Authorization"),
68 FORWARDED("Forwarded"),
72 IF_MODIFIED_SINCE("If-Modified-Since"),
73 IF_NONE_MATCH("If-None-Match"),
75 IF_UNMODIFIED_SINCE("If-Unmodified-Since"),
76 KEEP_ALIVE("Keep-Alive"),
77 MAX_FORWARDS("Max-Forwards"),
78 PROXY_AUTHORIZATION("Proxy-Authorization"),
80 REQUEST_RANGE("Request-Range"),
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"),
89 /* ------------------------------------------------------------ */
92 ACCEPT_RANGES("Accept-Ranges"),
96 PROXY_AUTHENTICATE("Proxy-Authenticate"),
97 RETRY_AFTER("Retry-After"),
99 SERVLET_ENGINE("Servlet-Engine"),
101 WWW_AUTHENTICATE("WWW-Authenticate"),
103 /* ------------------------------------------------------------ */
107 SET_COOKIE("Set-Cookie"),
108 SET_COOKIE2("Set-Cookie2"),
109 MIME_VERSION("MIME-Version"),
110 IDENTITY("identity"),
112 X_POWERED_BY("X-Powered-By"),
114 UNKNOWN("::UNKNOWN::");
117 /* ------------------------------------------------------------ */
118 public final static Trie<HttpHeader> CACHE= new ArrayTrie<>(512);
121 for (HttpHeader header : HttpHeader.values())
123 CACHE.put(header.toString(),header);
126 private final String _string;
127 private final byte[] _bytes;
128 private final byte[] _bytesColonSpace;
129 private final ByteBuffer _buffer;
131 /* ------------------------------------------------------------ */
135 _bytes=StringUtil.getBytes(s);
136 _bytesColonSpace=StringUtil.getBytes(s+": ");
137 _buffer=ByteBuffer.wrap(_bytes);
140 /* ------------------------------------------------------------ */
141 public ByteBuffer toBuffer()
143 return _buffer.asReadOnlyBuffer();
146 /* ------------------------------------------------------------ */
147 public byte[] getBytes()
152 /* ------------------------------------------------------------ */
153 public byte[] getBytesColonSpace()
155 return _bytesColonSpace;
158 /* ------------------------------------------------------------ */
159 public boolean is(String s)
161 return _string.equalsIgnoreCase(s);
164 /* ------------------------------------------------------------ */
165 public String asString()
170 /* ------------------------------------------------------------ */
172 public String toString()