1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.http;
17
18 import static java.util.Objects.requireNonNull;
19
20
21
22
23 public abstract class DefaultHttpMessage extends DefaultHttpObject implements HttpMessage {
24 private static final int HASH_CODE_PRIME = 31;
25 private HttpVersion version;
26 private final HttpHeaders headers;
27
28
29
30
31 protected DefaultHttpMessage(final HttpVersion version) {
32 this(version, true, false);
33 }
34
35
36
37
38 protected DefaultHttpMessage(final HttpVersion version, boolean validateHeaders, boolean singleFieldHeaders) {
39 this(version,
40 singleFieldHeaders ? new CombinedHttpHeaders(validateHeaders)
41 : new DefaultHttpHeaders(validateHeaders));
42 }
43
44
45
46
47 protected DefaultHttpMessage(final HttpVersion version, HttpHeaders headers) {
48 this.version = requireNonNull(version, "version");
49 this.headers = requireNonNull(headers, "headers");
50 }
51
52 @Override
53 public HttpHeaders headers() {
54 return headers;
55 }
56
57 @Override
58 @Deprecated
59 public HttpVersion getProtocolVersion() {
60 return protocolVersion();
61 }
62
63 @Override
64 public HttpVersion protocolVersion() {
65 return version;
66 }
67
68 @Override
69 public int hashCode() {
70 int result = 1;
71 result = HASH_CODE_PRIME * result + headers.hashCode();
72 result = HASH_CODE_PRIME * result + version.hashCode();
73 result = HASH_CODE_PRIME * result + super.hashCode();
74 return result;
75 }
76
77 @Override
78 public boolean equals(Object o) {
79 if (!(o instanceof DefaultHttpMessage)) {
80 return false;
81 }
82
83 DefaultHttpMessage other = (DefaultHttpMessage) o;
84
85 return headers().equals(other.headers()) &&
86 protocolVersion().equals(other.protocolVersion()) &&
87 super.equals(o);
88 }
89
90 @Override
91 public HttpMessage setProtocolVersion(HttpVersion version) {
92 requireNonNull(version, "version");
93 this.version = version;
94 return this;
95 }
96 }