1
16 package io.netty.handler.codec.http;
17
18 import io.netty.util.internal.ObjectUtil;
19
20 import static io.netty.util.internal.ObjectUtil.checkNotNull;
21
22
25 public class DefaultHttpRequest extends DefaultHttpMessage implements HttpRequest {
26 private static final int HASH_CODE_PRIME = 31;
27 private HttpMethod method;
28 private String uri;
29
30
37 public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) {
38 this(httpVersion, method, uri, true);
39 }
40
41
49 public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, boolean validateHeaders) {
50 super(httpVersion, validateHeaders, false);
51 this.method = checkNotNull(method, "method");
52 this.uri = checkNotNull(uri, "uri");
53 }
54
55
63 public DefaultHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, HttpHeaders headers) {
64 super(httpVersion, headers);
65 this.method = checkNotNull(method, "method");
66 this.uri = checkNotNull(uri, "uri");
67 }
68
69 @Override
70 @Deprecated
71 public HttpMethod getMethod() {
72 return method();
73 }
74
75 @Override
76 public HttpMethod method() {
77 return method;
78 }
79
80 @Override
81 @Deprecated
82 public String getUri() {
83 return uri();
84 }
85
86 @Override
87 public String uri() {
88 return uri;
89 }
90
91 @Override
92 public HttpRequest setMethod(HttpMethod method) {
93 this.method = ObjectUtil.checkNotNull(method, "method");
94 return this;
95 }
96
97 @Override
98 public HttpRequest setUri(String uri) {
99 this.uri = ObjectUtil.checkNotNull(uri, "uri");
100 return this;
101 }
102
103 @Override
104 public HttpRequest setProtocolVersion(HttpVersion version) {
105 super.setProtocolVersion(version);
106 return this;
107 }
108
109 @Override
110 public int hashCode() {
111 int result = 1;
112 result = HASH_CODE_PRIME * result + method.hashCode();
113 result = HASH_CODE_PRIME * result + uri.hashCode();
114 result = HASH_CODE_PRIME * result + super.hashCode();
115 return result;
116 }
117
118 @Override
119 public boolean equals(Object o) {
120 if (!(o instanceof DefaultHttpRequest)) {
121 return false;
122 }
123
124 DefaultHttpRequest other = (DefaultHttpRequest) o;
125
126 return method().equals(other.method()) &&
127 uri().equalsIgnoreCase(other.uri()) &&
128 super.equals(o);
129 }
130
131 @Override
132 public String toString() {
133 return HttpMessageUtil.appendRequest(new StringBuilder(256), this).toString();
134 }
135 }
136