View Javadoc
1   /*
2    * Copyright 2014 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at:
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  
16  package io.netty.handler.codec.http2;
17  
18  import io.netty.handler.codec.AsciiString;
19  import io.netty.handler.codec.BinaryHeaders;
20  
21  import java.util.HashSet;
22  import java.util.Set;
23  
24  /**
25   * A collection of headers sent or received via HTTP/2.
26   */
27  public interface Http2Headers extends BinaryHeaders {
28  
29      /**
30       * HTTP/2 pseudo-headers names.
31       */
32      enum PseudoHeaderName {
33          /**
34           * {@code :method}.
35           */
36          METHOD(":method"),
37  
38          /**
39           * {@code :scheme}.
40           */
41          SCHEME(":scheme"),
42  
43          /**
44           * {@code :authority}.
45           */
46          AUTHORITY(":authority"),
47  
48          /**
49           * {@code :path}.
50           */
51          PATH(":path"),
52  
53          /**
54           * {@code :status}.
55           */
56          STATUS(":status");
57  
58          private final AsciiString value;
59          private static final Set<AsciiString> PSEUDO_HEADERS = new HashSet<AsciiString>();
60          static {
61              for (PseudoHeaderName pseudoHeader : PseudoHeaderName.values()) {
62                  PSEUDO_HEADERS.add(pseudoHeader.value());
63              }
64          }
65  
66          PseudoHeaderName(String value) {
67              this.value = new AsciiString(value);
68          }
69  
70          public AsciiString value() {
71              // Return a slice so that the buffer gets its own reader index.
72              return value;
73          }
74  
75          /**
76           * Indicates whether the given header name is a valid HTTP/2 pseudo header.
77           */
78          public static boolean isPseudoHeader(AsciiString header) {
79              return PSEUDO_HEADERS.contains(header);
80          }
81      }
82  
83      @Override
84      Http2Headers add(AsciiString name, AsciiString value);
85  
86      @Override
87      Http2Headers add(AsciiString name, Iterable<? extends AsciiString> values);
88  
89      @Override
90      Http2Headers add(AsciiString name, AsciiString... values);
91  
92      @Override
93      Http2Headers addObject(AsciiString name, Object value);
94  
95      @Override
96      Http2Headers addObject(AsciiString name, Iterable<?> values);
97  
98      @Override
99      Http2Headers addObject(AsciiString name, Object... values);
100 
101     @Override
102     Http2Headers addBoolean(AsciiString name, boolean value);
103 
104     @Override
105     Http2Headers addByte(AsciiString name, byte value);
106 
107     @Override
108     Http2Headers addChar(AsciiString name, char value);
109 
110     @Override
111     Http2Headers addShort(AsciiString name, short value);
112 
113     @Override
114     Http2Headers addInt(AsciiString name, int value);
115 
116     @Override
117     Http2Headers addLong(AsciiString name, long value);
118 
119     @Override
120     Http2Headers addFloat(AsciiString name, float value);
121 
122     @Override
123     Http2Headers addDouble(AsciiString name, double value);
124 
125     @Override
126     Http2Headers addTimeMillis(AsciiString name, long value);
127 
128     @Override
129     Http2Headers add(BinaryHeaders headers);
130 
131     @Override
132     Http2Headers set(AsciiString name, AsciiString value);
133 
134     @Override
135     Http2Headers set(AsciiString name, Iterable<? extends AsciiString> values);
136 
137     @Override
138     Http2Headers set(AsciiString name, AsciiString... values);
139 
140     @Override
141     Http2Headers setObject(AsciiString name, Object value);
142 
143     @Override
144     Http2Headers setObject(AsciiString name, Iterable<?> values);
145 
146     @Override
147     Http2Headers setObject(AsciiString name, Object... values);
148 
149     @Override
150     Http2Headers setBoolean(AsciiString name, boolean value);
151 
152     @Override
153     Http2Headers setByte(AsciiString name, byte value);
154 
155     @Override
156     Http2Headers setChar(AsciiString name, char value);
157 
158     @Override
159     Http2Headers setShort(AsciiString name, short value);
160 
161     @Override
162     Http2Headers setInt(AsciiString name, int value);
163 
164     @Override
165     Http2Headers setLong(AsciiString name, long value);
166 
167     @Override
168     Http2Headers setFloat(AsciiString name, float value);
169 
170     @Override
171     Http2Headers setDouble(AsciiString name, double value);
172 
173     @Override
174     Http2Headers setTimeMillis(AsciiString name, long value);
175 
176     @Override
177     Http2Headers set(BinaryHeaders headers);
178 
179     @Override
180     Http2Headers setAll(BinaryHeaders headers);
181 
182     @Override
183     Http2Headers clear();
184 
185     /**
186      * Sets the {@link PseudoHeaderName#METHOD} header or {@code null} if there is no such header
187      */
188     Http2Headers method(AsciiString value);
189 
190     /**
191      * Sets the {@link PseudoHeaderName#SCHEME} header if there is no such header
192      */
193     Http2Headers scheme(AsciiString value);
194 
195     /**
196      * Sets the {@link PseudoHeaderName#AUTHORITY} header or {@code null} if there is no such header
197      */
198     Http2Headers authority(AsciiString value);
199 
200     /**
201      * Sets the {@link PseudoHeaderName#PATH} header or {@code null} if there is no such header
202      */
203     Http2Headers path(AsciiString value);
204 
205     /**
206      * Sets the {@link PseudoHeaderName#STATUS} header or {@code null} if there is no such header
207      */
208     Http2Headers status(AsciiString value);
209 
210     /**
211      * Gets the {@link PseudoHeaderName#METHOD} header or {@code null} if there is no such header
212      */
213     AsciiString method();
214 
215     /**
216      * Gets the {@link PseudoHeaderName#SCHEME} header or {@code null} if there is no such header
217      */
218     AsciiString scheme();
219 
220     /**
221      * Gets the {@link PseudoHeaderName#AUTHORITY} header or {@code null} if there is no such header
222      */
223     AsciiString authority();
224 
225     /**
226      * Gets the {@link PseudoHeaderName#PATH} header or {@code null} if there is no such header
227      */
228     AsciiString path();
229 
230     /**
231      * Gets the {@link PseudoHeaderName#STATUS} header or {@code null} if there is no such header
232      */
233     AsciiString status();
234 }