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 class DefaultHttpResponse extends DefaultHttpMessage implements HttpResponse {
24
25 private HttpResponseStatus status;
26
27
28
29
30
31
32
33 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status) {
34 this(version, status, true, false);
35 }
36
37
38
39
40
41
42
43
44 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, boolean validateHeaders) {
45 this(version, status, validateHeaders, false);
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, boolean validateHeaders,
61 boolean singleFieldHeaders) {
62 super(version, validateHeaders, singleFieldHeaders);
63 this.status = requireNonNull(status, "status");
64 }
65
66
67
68
69
70
71
72
73 public DefaultHttpResponse(HttpVersion version, HttpResponseStatus status, HttpHeaders headers) {
74 super(version, headers);
75 this.status = requireNonNull(status, "status");
76 }
77
78 @Override
79 public HttpResponseStatus status() {
80 return status;
81 }
82
83 @Override
84 public HttpResponse setStatus(HttpResponseStatus status) {
85 requireNonNull(status, "status");
86 this.status = status;
87 return this;
88 }
89
90 @Override
91 public HttpResponse setProtocolVersion(HttpVersion version) {
92 super.setProtocolVersion(version);
93 return this;
94 }
95
96 @Override
97 public String toString() {
98 return HttpMessageUtil.appendResponse(new StringBuilder(256), this).toString();
99 }
100
101 @Override
102 public int hashCode() {
103 int result = 1;
104 result = 31 * result + status.hashCode();
105 result = 31 * result + super.hashCode();
106 return result;
107 }
108
109 @Override
110 public boolean equals(Object o) {
111 if (!(o instanceof DefaultHttpResponse)) {
112 return false;
113 }
114
115 DefaultHttpResponse other = (DefaultHttpResponse) o;
116
117 return status.equals(other.status()) && super.equals(o);
118 }
119 }