1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http;
17
18 import static io.netty.util.internal.ObjectUtil.checkNotNull;
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, DefaultHttpHeadersFactory.headersFactory());
33 }
34
35
36
37
38
39
40
41
42 @Deprecated
43 protected DefaultHttpMessage(final HttpVersion version, boolean validateHeaders, boolean singleFieldHeaders) {
44 this(version, DefaultHttpHeadersFactory.headersFactory()
45 .withValidation(validateHeaders)
46 .withCombiningHeaders(singleFieldHeaders));
47 }
48
49
50
51
52 protected DefaultHttpMessage(HttpVersion version, HttpHeadersFactory headersFactory) {
53 this(version, headersFactory.newHeaders());
54 }
55
56
57
58
59 protected DefaultHttpMessage(final HttpVersion version, HttpHeaders headers) {
60 this.version = checkNotNull(version, "version");
61 this.headers = checkNotNull(headers, "headers");
62 }
63
64 @Override
65 public HttpHeaders headers() {
66 return headers;
67 }
68
69 @Override
70 @Deprecated
71 public HttpVersion getProtocolVersion() {
72 return protocolVersion();
73 }
74
75 @Override
76 public HttpVersion protocolVersion() {
77 return version;
78 }
79
80 @Override
81 public int hashCode() {
82 int result = 1;
83 result = HASH_CODE_PRIME * result + headers.hashCode();
84 result = HASH_CODE_PRIME * result + version.hashCode();
85 result = HASH_CODE_PRIME * result + super.hashCode();
86 return result;
87 }
88
89 @Override
90 public boolean equals(Object o) {
91 if (!(o instanceof DefaultHttpMessage)) {
92 return false;
93 }
94
95 DefaultHttpMessage other = (DefaultHttpMessage) o;
96
97 return headers().equals(other.headers()) &&
98 protocolVersion().equals(other.protocolVersion()) &&
99 super.equals(o);
100 }
101
102 @Override
103 public HttpMessage setProtocolVersion(HttpVersion version) {
104 this.version = checkNotNull(version, "version");
105 return this;
106 }
107 }