View Javadoc
1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a 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
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.spdy;
17  
18  import io.netty.handler.codec.AsciiString;
19  import io.netty.handler.codec.DefaultTextHeaders;
20  import io.netty.handler.codec.Headers;
21  import io.netty.handler.codec.TextHeaders;
22  
23  import java.util.Locale;
24  
25  public class DefaultSpdyHeaders extends DefaultTextHeaders implements SpdyHeaders {
26      private static final Headers.ValueConverter<CharSequence> SPDY_VALUE_CONVERTER =
27              new DefaultTextValueTypeConverter() {
28          @Override
29          public CharSequence convertObject(Object value) {
30              CharSequence seq;
31              if (value instanceof CharSequence) {
32                  seq = (CharSequence) value;
33              } else {
34                  seq = value.toString();
35              }
36  
37              SpdyCodecUtil.validateHeaderValue(seq);
38              return seq;
39          }
40      };
41  
42      private static final NameConverter<CharSequence> SPDY_NAME_CONVERTER = new NameConverter<CharSequence>() {
43          @Override
44          public CharSequence convertName(CharSequence name) {
45              if (name instanceof AsciiString) {
46                  name = ((AsciiString) name).toLowerCase();
47              } else {
48                  name = name.toString().toLowerCase(Locale.US);
49              }
50              SpdyCodecUtil.validateHeaderName(name);
51              return name;
52          }
53      };
54  
55      public DefaultSpdyHeaders() {
56          super(true, SPDY_VALUE_CONVERTER, SPDY_NAME_CONVERTER);
57      }
58  
59      @Override
60      public SpdyHeaders add(CharSequence name, CharSequence value) {
61          super.add(name, value);
62          return this;
63      }
64  
65      @Override
66      public SpdyHeaders add(CharSequence name, Iterable<? extends CharSequence> values) {
67          super.add(name, values);
68          return this;
69      }
70  
71      @Override
72      public SpdyHeaders add(CharSequence name, CharSequence... values) {
73          super.add(name, values);
74          return this;
75      }
76  
77      @Override
78      public SpdyHeaders addObject(CharSequence name, Object value) {
79          super.addObject(name, value);
80          return this;
81      }
82  
83      @Override
84      public SpdyHeaders addObject(CharSequence name, Iterable<?> values) {
85          super.addObject(name, values);
86          return this;
87      }
88  
89      @Override
90      public SpdyHeaders addObject(CharSequence name, Object... values) {
91          super.addObject(name, values);
92          return this;
93      }
94  
95      @Override
96      public SpdyHeaders addBoolean(CharSequence name, boolean value) {
97          super.addBoolean(name, value);
98          return this;
99      }
100 
101     @Override
102     public SpdyHeaders addChar(CharSequence name, char value) {
103         super.addChar(name, value);
104         return this;
105     }
106 
107     @Override
108     public SpdyHeaders addByte(CharSequence name, byte value) {
109         super.addByte(name, value);
110         return this;
111     }
112 
113     @Override
114     public SpdyHeaders addShort(CharSequence name, short value) {
115         super.addShort(name, value);
116         return this;
117     }
118 
119     @Override
120     public SpdyHeaders addInt(CharSequence name, int value) {
121         super.addInt(name, value);
122         return this;
123     }
124 
125     @Override
126     public SpdyHeaders addLong(CharSequence name, long value) {
127         super.addLong(name, value);
128         return this;
129     }
130 
131     @Override
132     public SpdyHeaders addFloat(CharSequence name, float value) {
133         super.addFloat(name, value);
134         return this;
135     }
136 
137     @Override
138     public SpdyHeaders addDouble(CharSequence name, double value) {
139         super.addDouble(name, value);
140         return this;
141     }
142 
143     @Override
144     public SpdyHeaders addTimeMillis(CharSequence name, long value) {
145         super.addTimeMillis(name, value);
146         return this;
147     }
148 
149     @Override
150     public SpdyHeaders add(TextHeaders headers) {
151         super.add(headers);
152         return this;
153     }
154 
155     @Override
156     public SpdyHeaders set(CharSequence name, CharSequence value) {
157         super.set(name, value);
158         return this;
159     }
160 
161     @Override
162     public SpdyHeaders set(CharSequence name, Iterable<? extends CharSequence> values) {
163         super.set(name, values);
164         return this;
165     }
166 
167     @Override
168     public SpdyHeaders set(CharSequence name, CharSequence... values) {
169         super.set(name, values);
170         return this;
171     }
172 
173     @Override
174     public SpdyHeaders setObject(CharSequence name, Object value) {
175         super.setObject(name, value);
176         return this;
177     }
178 
179     @Override
180     public SpdyHeaders setObject(CharSequence name, Iterable<?> values) {
181         super.setObject(name, values);
182         return this;
183     }
184 
185     @Override
186     public SpdyHeaders setObject(CharSequence name, Object... values) {
187         super.setObject(name, values);
188         return this;
189     }
190 
191     @Override
192     public SpdyHeaders setBoolean(CharSequence name, boolean value) {
193         super.setBoolean(name, value);
194         return this;
195     }
196 
197     @Override
198     public SpdyHeaders setChar(CharSequence name, char value) {
199         super.setChar(name, value);
200         return this;
201     }
202 
203     @Override
204     public SpdyHeaders setByte(CharSequence name, byte value) {
205         super.setByte(name, value);
206         return this;
207     }
208 
209     @Override
210     public SpdyHeaders setShort(CharSequence name, short value) {
211         super.setShort(name, value);
212         return this;
213     }
214 
215     @Override
216     public SpdyHeaders setInt(CharSequence name, int value) {
217         super.setInt(name, value);
218         return this;
219     }
220 
221     @Override
222     public SpdyHeaders setLong(CharSequence name, long value) {
223         super.setLong(name, value);
224         return this;
225     }
226 
227     @Override
228     public SpdyHeaders setFloat(CharSequence name, float value) {
229         super.setFloat(name, value);
230         return this;
231     }
232 
233     @Override
234     public SpdyHeaders setDouble(CharSequence name, double value) {
235         super.setDouble(name, value);
236         return this;
237     }
238 
239     @Override
240     public SpdyHeaders setTimeMillis(CharSequence name, long value) {
241         super.setTimeMillis(name, value);
242         return this;
243     }
244 
245     @Override
246     public SpdyHeaders set(TextHeaders headers) {
247         super.set(headers);
248         return this;
249     }
250 
251     @Override
252     public SpdyHeaders setAll(TextHeaders headers) {
253         super.setAll(headers);
254         return this;
255     }
256 
257     @Override
258     public SpdyHeaders clear() {
259         super.clear();
260         return this;
261     }
262 }