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