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.util.internal.StringUtil;
19
20 import java.util.Map;
21
22
23
24
25 public class DefaultSpdyHeadersFrame extends DefaultSpdyStreamFrame
26 implements SpdyHeadersFrame {
27
28 private boolean invalid;
29 private boolean truncated;
30 private final SpdyHeaders headers;
31
32
33
34
35
36
37 public DefaultSpdyHeadersFrame(int streamId) {
38 this(streamId, true);
39 }
40
41
42
43
44
45
46
47 public DefaultSpdyHeadersFrame(int streamId, boolean validate) {
48 super(streamId);
49 headers = new DefaultSpdyHeaders(validate);
50 }
51
52 @Override
53 public SpdyHeadersFrame setStreamId(int streamId) {
54 super.setStreamId(streamId);
55 return this;
56 }
57
58 @Override
59 public SpdyHeadersFrame setLast(boolean last) {
60 super.setLast(last);
61 return this;
62 }
63
64 @Override
65 public boolean isInvalid() {
66 return invalid;
67 }
68
69 @Override
70 public SpdyHeadersFrame setInvalid() {
71 invalid = true;
72 return this;
73 }
74
75 @Override
76 public boolean isTruncated() {
77 return truncated;
78 }
79
80 @Override
81 public SpdyHeadersFrame setTruncated() {
82 truncated = true;
83 return this;
84 }
85
86 @Override
87 public SpdyHeaders headers() {
88 return headers;
89 }
90
91 @Override
92 public String toString() {
93 StringBuilder buf = new StringBuilder()
94 .append(StringUtil.simpleClassName(this))
95 .append("(last: ")
96 .append(isLast())
97 .append(')')
98 .append(StringUtil.NEWLINE)
99 .append("--> Stream-ID = ")
100 .append(streamId())
101 .append(StringUtil.NEWLINE)
102 .append("--> Headers:")
103 .append(StringUtil.NEWLINE);
104 appendHeaders(buf);
105
106
107 buf.setLength(buf.length() - StringUtil.NEWLINE.length());
108 return buf.toString();
109 }
110
111 protected void appendHeaders(StringBuilder buf) {
112 for (Map.Entry<CharSequence, CharSequence> e: headers()) {
113 buf.append(" ");
114 buf.append(e.getKey());
115 buf.append(": ");
116 buf.append(e.getValue());
117 buf.append(StringUtil.NEWLINE);
118 }
119 }
120 }