1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.spdy;
17
18 import io.netty.handler.codec.CharSequenceValueConverter;
19 import io.netty.handler.codec.DefaultHeaders;
20 import io.netty.handler.codec.HeadersUtils;
21
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map.Entry;
25
26 import static io.netty.util.AsciiString.CASE_INSENSITIVE_HASHER;
27 import static io.netty.util.AsciiString.CASE_SENSITIVE_HASHER;
28
29 public class DefaultSpdyHeaders extends DefaultHeaders<CharSequence, CharSequence, SpdyHeaders> implements SpdyHeaders {
30 private static final NameValidator<CharSequence> SpdyNameValidator = new NameValidator<CharSequence>() {
31 @Override
32 public void validateName(CharSequence name) {
33 SpdyCodecUtil.validateHeaderName(name);
34 }
35 };
36
37 public DefaultSpdyHeaders() {
38 this(true);
39 }
40
41 @SuppressWarnings("unchecked")
42 public DefaultSpdyHeaders(boolean validate) {
43 super(CASE_INSENSITIVE_HASHER,
44 validate ? HeaderValueConverterAndValidator.INSTANCE : CharSequenceValueConverter.INSTANCE,
45 validate ? SpdyNameValidator : NameValidator.NOT_NULL);
46 }
47
48 @Override
49 public String getAsString(CharSequence name) {
50 return HeadersUtils.getAsString(this, name);
51 }
52
53 @Override
54 public List<String> getAllAsString(CharSequence name) {
55 return HeadersUtils.getAllAsString(this, name);
56 }
57
58 @Override
59 public Iterator<Entry<String, String>> iteratorAsString() {
60 return HeadersUtils.iteratorAsString(this);
61 }
62
63 @Override
64 public boolean contains(CharSequence name, CharSequence value) {
65 return contains(name, value, false);
66 }
67
68 @Override
69 public boolean contains(CharSequence name, CharSequence value, boolean ignoreCase) {
70 return contains(name, value,
71 ignoreCase ? CASE_INSENSITIVE_HASHER : CASE_SENSITIVE_HASHER);
72 }
73
74 private static final class HeaderValueConverterAndValidator extends CharSequenceValueConverter {
75 public static final HeaderValueConverterAndValidator INSTANCE = new HeaderValueConverterAndValidator();
76
77 @Override
78 public CharSequence convertObject(Object value) {
79 final CharSequence seq = super.convertObject(value);
80 SpdyCodecUtil.validateHeaderValue(seq);
81 return seq;
82 }
83 }
84 }