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 io.netty.util.internal.ObjectUtil;
19
20 import static io.netty.handler.codec.http.DefaultHttpHeadersFactory.headersFactory;
21 import static io.netty.util.internal.ObjectUtil.checkNotNull;
22
23
24
25
26 public class DefaultHttpResponse extends DefaultHttpMessage implements HttpResponse {
27
28 private HttpResponseStatus status;
29
30
31
32
33
34
35
36 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status) {
37 this(version, status, headersFactory());
38 }
39
40
41
42
43
44
45
46
47
48
49 @Deprecated
50 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, boolean validateHeaders) {
51 this(version, status, headersFactory().withValidation(validateHeaders));
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 @Deprecated
69 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, boolean validateHeaders,
70 boolean singleFieldHeaders) {
71 this(version, status, headersFactory().withValidation(validateHeaders)
72 .withCombiningHeaders(singleFieldHeaders));
73 }
74
75
76
77
78
79
80
81
82
83 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, HttpHeadersFactory headersFactory) {
84 this(version, status, headersFactory.newHeaders());
85 }
86
87
88
89
90
91
92
93
94 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, HttpHeaders headers) {
95 super(version, headers);
96 this.status = checkNotNull(status, "status");
97 }
98
99 @Override
100 @Deprecated
101 public HttpResponseStatus getStatus() {
102 return status();
103 }
104
105 @Override
106 public HttpResponseStatus status() {
107 return status;
108 }
109
110 @Override
111 public HttpResponse setStatus(HttpResponseStatus status) {
112 this.status = ObjectUtil.checkNotNull(status, "status");
113 return this;
114 }
115
116 @Override
117 public HttpResponse setProtocolVersion(HttpVersion version) {
118 super.setProtocolVersion(version);
119 return this;
120 }
121
122 @Override
123 public String toString() {
124 return HttpMessageUtil.appendResponse(new StringBuilder(256), this).toString();
125 }
126
127 @Override
128 public int hashCode() {
129 int result = 1;
130 result = 31 * result + status.hashCode();
131 result = 31 * result + super.hashCode();
132 return result;
133 }
134
135 @Override
136 public boolean equals(Object o) {
137 if (!(o instanceof DefaultHttpResponse)) {
138 return false;
139 }
140
141 DefaultHttpResponse other = (DefaultHttpResponse) o;
142
143 return status.equals(other.status()) && super.equals(o);
144 }
145 }