]> WPIA git - gigi.git/blob - lib/jetty/org/eclipse/jetty/http/HttpHeader.java
Update notes about password security
[gigi.git] / lib / jetty / org / eclipse / jetty / http / HttpHeader.java
1 //
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.
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 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     /** General Fields.
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     /** Entity Fields.
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     /** Request Fields.
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     /** Response Fields.
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     /** Other Fields.
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
114     UNKNOWN("::UNKNOWN::");
115
116
117     /* ------------------------------------------------------------ */
118     public final static Trie<HttpHeader> CACHE= new ArrayTrie<>(512);
119     static
120     {
121         for (HttpHeader header : HttpHeader.values())
122             if (header!=UNKNOWN)
123                 CACHE.put(header.toString(),header);
124     }
125     
126     private final String _string;
127     private final byte[] _bytes;
128     private final byte[] _bytesColonSpace;
129     private final ByteBuffer _buffer;
130
131     /* ------------------------------------------------------------ */
132     HttpHeader(String s)
133     {
134         _string=s;
135         _bytes=StringUtil.getBytes(s);
136         _bytesColonSpace=StringUtil.getBytes(s+": ");
137         _buffer=ByteBuffer.wrap(_bytes);
138     }
139
140     /* ------------------------------------------------------------ */
141     public ByteBuffer toBuffer()
142     {
143         return _buffer.asReadOnlyBuffer();
144     }
145
146     /* ------------------------------------------------------------ */
147     public byte[] getBytes()
148     {
149         return _bytes;
150     }
151
152     /* ------------------------------------------------------------ */
153     public byte[] getBytesColonSpace()
154     {
155         return _bytesColonSpace;
156     }
157
158     /* ------------------------------------------------------------ */
159     public boolean is(String s)
160     {
161         return _string.equalsIgnoreCase(s);    
162     }
163
164     /* ------------------------------------------------------------ */
165     public String asString()
166     {
167         return _string;
168     }
169     
170     /* ------------------------------------------------------------ */
171     @Override
172     public String toString()
173     {
174         return _string;
175     }
176     
177 }
178