]> WPIA git - gigi.git/blob - lib/jetty/org/eclipse/jetty/http/HttpHeaderValue.java
updating jetty to jetty-9.2.16.v2016040
[gigi.git] / lib / jetty / org / eclipse / jetty / http / HttpHeaderValue.java
1 //
2 //  ========================================================================
3 //  Copyright (c) 1995-2016 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 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 }