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