1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.http2;
17
18 import io.netty5.util.internal.StringUtil;
19 import io.netty5.util.internal.UnstableApi;
20
21 import static io.netty5.handler.codec.http2.Http2CodecUtil.verifyPadding;
22 import static java.util.Objects.requireNonNull;
23
24
25
26
27 @UnstableApi
28 public final class DefaultHttp2HeadersFrame extends AbstractHttp2StreamFrame implements Http2HeadersFrame {
29 private final Http2Headers headers;
30 private final boolean endStream;
31 private final int padding;
32
33
34
35
36
37
38 public DefaultHttp2HeadersFrame(Http2Headers headers) {
39 this(headers, false);
40 }
41
42
43
44
45
46
47 public DefaultHttp2HeadersFrame(Http2Headers headers, boolean endStream) {
48 this(headers, endStream, 0);
49 }
50
51
52
53
54
55
56
57
58
59 public DefaultHttp2HeadersFrame(Http2Headers headers, boolean endStream, int padding) {
60 this.headers = requireNonNull(headers, "headers");
61 this.endStream = endStream;
62 verifyPadding(padding);
63 this.padding = padding;
64 }
65
66 @Override
67 public DefaultHttp2HeadersFrame stream(Http2FrameStream stream) {
68 super.stream(stream);
69 return this;
70 }
71
72 @Override
73 public String name() {
74 return "HEADERS";
75 }
76
77 @Override
78 public Http2Headers headers() {
79 return headers;
80 }
81
82 @Override
83 public boolean isEndStream() {
84 return endStream;
85 }
86
87 @Override
88 public int padding() {
89 return padding;
90 }
91
92 @Override
93 public String toString() {
94 return StringUtil.simpleClassName(this) + "(stream=" + stream() + ", headers=" + headers
95 + ", endStream=" + endStream + ", padding=" + padding + ')';
96 }
97
98 @Override
99 public boolean equals(Object o) {
100 if (!(o instanceof DefaultHttp2HeadersFrame)) {
101 return false;
102 }
103 DefaultHttp2HeadersFrame other = (DefaultHttp2HeadersFrame) o;
104 return super.equals(other) && headers.equals(other.headers)
105 && endStream == other.endStream && padding == other.padding;
106 }
107
108 @Override
109 public int hashCode() {
110 int hash = super.hashCode();
111 hash = hash * 31 + headers.hashCode();
112 hash = hash * 31 + (endStream ? 0 : 1);
113 hash = hash * 31 + padding;
114 return hash;
115 }
116 }