Skip to content

Commit ce87830

Browse files
committed
Rename RequestType to RequestMethod
Method seems to be a more standard term than "Type". We wanted to keep the term "Request" (rather than Http) since it is a parameter that is only valid for the request.
1 parent 8164dd7 commit ce87830

File tree

10 files changed

+90
-76
lines changed

10 files changed

+90
-76
lines changed

client/src/main/java/org/threadly/litesockets/client/http/HTTPClient.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.threadly.litesockets.protocols.http.response.HTTPResponseProcessor.HTTPResponseCallback;
3737
import org.threadly.litesockets.protocols.http.shared.HTTPAddress;
3838
import org.threadly.litesockets.protocols.http.shared.HTTPParsingException;
39-
import org.threadly.litesockets.protocols.http.shared.HTTPRequestType;
39+
import org.threadly.litesockets.protocols.http.shared.HTTPRequestMethod;
4040
import org.threadly.litesockets.protocols.http.shared.HTTPResponseCode;
4141
import org.threadly.litesockets.protocols.ws.WebSocketFrameParser.WebSocketFrame;
4242
import org.threadly.litesockets.utils.IOUtils;
@@ -173,7 +173,8 @@ public void closeAllClients() {
173173
* @param timeout time in milliseconds to wait for HTTPRequests to finish.
174174
*/
175175
public void setTimeout(long timeout, TimeUnit unit) {
176-
this.defaultTimeoutMS = Math.min(Math.max(unit.toMillis(timeout),HTTPRequest.MIN_TIMEOUT_MS), HTTPRequest.MAX_TIMEOUT_MS);
176+
this.defaultTimeoutMS = Math.min(Math.max(unit.toMillis(timeout),HTTPRequest.MIN_TIMEOUT_MS),
177+
HTTPRequest.MAX_TIMEOUT_MS);
177178
}
178179

179180
public long getMaxIdleTimeout() {
@@ -210,22 +211,22 @@ public void run() {
210211
* @throws HTTPParsingException is thrown if the server sends back protocol or a response that is larger then allowed.
211212
*/
212213
public HTTPResponseData request(final URL url) throws HTTPParsingException {
213-
return request(url, HTTPRequestType.GET, IOUtils.EMPTY_BYTEBUFFER);
214+
return request(url, HTTPRequestMethod.GET, IOUtils.EMPTY_BYTEBUFFER);
214215
}
215216

216217
/**
217218
* Sends a blocking HTTP request.
218219
*
219220
* @param url the url to send the request too.
220-
* @param rt the {@link HTTPRequestType} to use on the request.
221+
* @param rm the {@link HTTPRequestMethod} to use on the request.
221222
* @param bb the data to put in the body for this request.
222223
* @return an {@link HTTPResponseData} object containing the headers and content of the response.
223224
* @throws HTTPParsingException is thrown if the server sends back protocol or a response that is larger then allowed.
224225
*/
225-
public HTTPResponseData request(final URL url, final HTTPRequestType rt, final ByteBuffer bb) throws HTTPParsingException {
226+
public HTTPResponseData request(final URL url, final HTTPRequestMethod rm, final ByteBuffer bb) throws HTTPParsingException {
226227
HTTPResponseData hr = null;
227228
try {
228-
hr = requestAsync(url, rt, bb).get();
229+
hr = requestAsync(url, rm, bb).get();
229230
} catch (InterruptedException e) {
230231
Thread.currentThread().interrupt();
231232
} catch (Exception e) {
@@ -275,21 +276,22 @@ public HTTPResponseData request(final ClientHTTPRequest request) throws HTTPPars
275276
* successfully or with errors.
276277
*/
277278
public ListenableFuture<HTTPResponseData> requestAsync(final URL url) {
278-
return requestAsync(url, HTTPRequestType.GET, IOUtils.EMPTY_BYTEBUFFER);
279+
return requestAsync(url, HTTPRequestMethod.GET, IOUtils.EMPTY_BYTEBUFFER);
279280
}
280281

281282
/**
282283
* Sends an asynchronous HTTP request.
283284
*
284285
* @param url the {@link URL} to send the request too.
285-
* @param rt the {@link HTTPRequestType} to use on the request.
286+
* @param rm the {@link HTTPRequestMethod} to use on the request.
286287
* @param bb the data to put in the body for this request.
287288
* @return an {@link ListenableFuture} containing a {@link HTTPResponseData} object that will be completed when the request is finished,
288289
* successfully or with errors.
289290
*/
290-
public ListenableFuture<HTTPResponseData> requestAsync(final URL url, final HTTPRequestType rt, final ByteBuffer bb) {
291+
public ListenableFuture<HTTPResponseData> requestAsync(final URL url, final HTTPRequestMethod rm,
292+
final ByteBuffer bb) {
291293
HTTPRequestBuilder hrb = new HTTPRequestBuilder(url);
292-
hrb.setRequestType(rt);
294+
hrb.setRequestMethod(rm);
293295
hrb.setTimeout(this.defaultTimeoutMS, TimeUnit.MILLISECONDS);
294296
if (bb != null && bb.hasRemaining()) {
295297
hrb.setBody(bb);
@@ -508,7 +510,7 @@ private class HTTPRequestWrapper implements HTTPResponseCallback {
508510
public HTTPRequestWrapper(ClientHTTPRequest chr) {
509511
hrp = new HTTPResponseProcessor(chr.getHTTPRequest()
510512
.getHTTPRequestHeader()
511-
.getRequestType().equals("HEAD"));
513+
.getRequestMethod().equals("HEAD"));
512514
hrp.addHTTPResponseCallback(this);
513515
this.chr = chr;
514516
}
@@ -567,7 +569,8 @@ public static class HTTPResponseData {
567569
private final MergedByteBuffers body;
568570
private final HTTPClient client;
569571

570-
public HTTPResponseData(HTTPClient client, HTTPRequest origRequest, HTTPResponse hr, MergedByteBuffers bb) {
572+
public HTTPResponseData(HTTPClient client, HTTPRequest origRequest, HTTPResponse hr,
573+
MergedByteBuffers bb) {
571574
this.client = client;
572575
this.hr = hr;
573576
this.body = bb;

client/src/main/java/org/threadly/litesockets/client/ws/WebSocketClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.threadly.litesockets.protocols.http.response.HTTPResponse;
2424
import org.threadly.litesockets.protocols.http.response.HTTPResponseBuilder;
2525
import org.threadly.litesockets.protocols.http.shared.HTTPConstants;
26-
import org.threadly.litesockets.protocols.http.shared.HTTPRequestType;
26+
import org.threadly.litesockets.protocols.http.shared.HTTPRequestMethod;
2727
import org.threadly.litesockets.protocols.http.shared.HTTPResponseCode;
2828
import org.threadly.litesockets.protocols.ws.WebSocketFrameParser;
2929
import org.threadly.litesockets.protocols.ws.WebSocketFrameParser.WebSocketFrame;
@@ -45,7 +45,7 @@ public class WebSocketClient implements StreamingClient {
4545
.setHeader(HTTPConstants.HTTP_KEY_WEBSOCKET_ACCEPT, "123456")
4646
.build();
4747
public static final HTTPRequest DEFAULT_WS_REQUEST = new HTTPRequestBuilder()
48-
.setRequestType(HTTPRequestType.GET)
48+
.setRequestMethod(HTTPRequestMethod.GET)
4949
.setHeader(HTTPConstants.HTTP_KEY_UPGRADE, "websocket")
5050
.setHeader(HTTPConstants.HTTP_KEY_CONNECTION, "Upgrade")
5151
.setHeader(HTTPConstants.HTTP_KEY_WEBSOCKET_VERSION, "13")

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group = org.threadly
2-
version = 0.14
2+
version = 0.15
33
threadlyVersion = 5.16
44
litesocketsVersion = 4.3
55
org.gradle.parallel=true

protocol/src/main/java/org/threadly/litesockets/protocols/http/request/HTTPRequestBuilder.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.threadly.litesockets.protocols.http.shared.HTTPAddress;
1313
import org.threadly.litesockets.protocols.http.shared.HTTPConstants;
1414
import org.threadly.litesockets.protocols.http.shared.HTTPHeaders;
15-
import org.threadly.litesockets.protocols.http.shared.HTTPRequestType;
15+
import org.threadly.litesockets.protocols.http.shared.HTTPRequestMethod;
1616
import org.threadly.litesockets.protocols.http.shared.HTTPUtils;
1717
import org.threadly.util.ArgumentVerifier;
1818

@@ -67,9 +67,9 @@ public HTTPRequestBuilder setURL(final URL url) {
6767
}
6868
String q = url.getQuery();
6969
if(q != null) {
70-
request = new HTTPRequestHeader(request.getRequestType(), tmpPath, HTTPUtils.queryToMap(q), request.getHttpVersion());
70+
request = new HTTPRequestHeader(request.getRequestMethod(), tmpPath, HTTPUtils.queryToMap(q), request.getHttpVersion());
7171
} else {
72-
request = new HTTPRequestHeader(request.getRequestType(), tmpPath, null, request.getHttpVersion());
72+
request = new HTTPRequestHeader(request.getRequestMethod(), tmpPath, null, request.getHttpVersion());
7373
}
7474
if(url.getProtocol().equalsIgnoreCase("https")) {
7575
doSSL = true;
@@ -91,13 +91,14 @@ public HTTPRequestBuilder setHTTPRequestHeader(final HTTPRequestHeader hrh) {
9191
}
9292

9393
/**
94-
* Sets the {@link HTTPRequestType} for this request. This will accept non-stander strings in the for the request.
94+
* Sets the {@link HTTPRequestMethod} for this request. This will accept non-stander strings in the for the request.
9595
*
96-
* @param rt the RequestType to set this request too.
96+
* @param rm the http request method to set this request too.
9797
* @return the current {@link HTTPRequestBuilder} object.
9898
*/
99-
public HTTPRequestBuilder setRequestType(final String rt) {
100-
this.request = new HTTPRequestHeader(rt, request.getRequestPath(), request.getRequestQuery(), request.getHttpVersion());
99+
public HTTPRequestBuilder setRequestMethod(final String rm) {
100+
this.request = new HTTPRequestHeader(rm, request.getRequestPath(), request.getRequestQuery(),
101+
request.getHttpVersion());
101102
return this;
102103
}
103104

@@ -108,7 +109,8 @@ public HTTPRequestBuilder setRequestType(final String rt) {
108109
* @return the current {@link HTTPRequestBuilder} object.
109110
*/
110111
public HTTPRequestBuilder setHTTPVersion(final String version) {
111-
this.request = new HTTPRequestHeader(request.getRequestType(), request.getRequestPath(), request.getRequestQuery(), version);
112+
this.request = new HTTPRequestHeader(request.getRequestMethod(), request.getRequestPath(),
113+
request.getRequestQuery(), version);
112114
return this;
113115
}
114116

@@ -122,9 +124,11 @@ public HTTPRequestBuilder setHTTPVersion(final String version) {
122124
*/
123125
public HTTPRequestBuilder setPath(final String path) {
124126
if(path.contains("?")) {
125-
this.request = new HTTPRequestHeader(request.getRequestType(), path, HTTPUtils.queryToMap(path), request.getHttpVersion());
127+
this.request = new HTTPRequestHeader(request.getRequestMethod(), path,
128+
HTTPUtils.queryToMap(path), request.getHttpVersion());
126129
} else {
127-
this.request = new HTTPRequestHeader(request.getRequestType(), path, request.getRequestQuery(), request.getHttpVersion());
130+
this.request = new HTTPRequestHeader(request.getRequestMethod(), path,
131+
request.getRequestQuery(), request.getHttpVersion());
128132
}
129133
return this;
130134
}
@@ -136,7 +140,7 @@ public HTTPRequestBuilder setPath(final String path) {
136140
* @return the current {@link HTTPRequestBuilder} object.
137141
*/
138142
public HTTPRequestBuilder setQueryString(final String query) {
139-
this.request = new HTTPRequestHeader(request.getRequestType(), request.getRequestPath(), HTTPUtils.queryToMap(query), request.getHttpVersion());
143+
this.request = new HTTPRequestHeader(request.getRequestMethod(), request.getRequestPath(), HTTPUtils.queryToMap(query), request.getHttpVersion());
140144
return this;
141145
}
142146

@@ -150,7 +154,7 @@ public HTTPRequestBuilder setQueryString(final String query) {
150154
public HTTPRequestBuilder appendQuery(final String key, final String value) {
151155
HashMap<String, String> map = new HashMap<String, String>(request.getRequestQuery());
152156
map.put(key, value);
153-
this.request = new HTTPRequestHeader(request.getRequestType(), request.getRequestPath(), map, request.getHttpVersion());
157+
this.request = new HTTPRequestHeader(request.getRequestMethod(), request.getRequestPath(), map, request.getHttpVersion());
154158
return this;
155159
}
156160

@@ -163,7 +167,7 @@ public HTTPRequestBuilder appendQuery(final String key, final String value) {
163167
public HTTPRequestBuilder removeQuery(final String key) {
164168
HashMap<String, String> map = new HashMap<String, String>(request.getRequestQuery());
165169
map.remove(key);
166-
this.request = new HTTPRequestHeader(request.getRequestType(), request.getRequestPath(), map, request.getHttpVersion());
170+
this.request = new HTTPRequestHeader(request.getRequestMethod(), request.getRequestPath(), map, request.getHttpVersion());
167171
return this;
168172
}
169173

@@ -301,13 +305,14 @@ public HTTPRequestBuilder replaceHTTPHeaders(final HTTPHeaders hh) {
301305

302306

303307
/**
304-
* Sets the {@link HTTPRequestType} for this request. This uses the standard http request types enum.
308+
* Sets the {@link HTTPRequestMethod} for this request. This uses the standard http request methods enum.
305309
*
306-
* @param rt the RequestType to set this request too.
310+
* @param rm the http request method to set this request too.
307311
* @return the current {@link HTTPRequestBuilder} object.
308312
*/
309-
public HTTPRequestBuilder setRequestType(final HTTPRequestType rt) {
310-
this.request = new HTTPRequestHeader(rt, request.getRequestPath(), request.getRequestQuery(), request.getHttpVersion());
313+
public HTTPRequestBuilder setRequestMethod(final HTTPRequestMethod rm) {
314+
this.request = new HTTPRequestHeader(rm, request.getRequestPath(), request.getRequestQuery(),
315+
request.getHttpVersion());
311316
return this;
312317
}
313318

protocol/src/main/java/org/threadly/litesockets/protocols/http/request/HTTPRequestHeader.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
import java.util.Map;
77

88
import org.threadly.litesockets.protocols.http.shared.HTTPConstants;
9-
import org.threadly.litesockets.protocols.http.shared.HTTPRequestType;
9+
import org.threadly.litesockets.protocols.http.shared.HTTPRequestMethod;
1010
import org.threadly.litesockets.protocols.http.shared.HTTPUtils;
1111

1212
/**
1313
* This is an immutable HTTP Request Header. Basically the first line of the http request.
1414
*
15-
* This is the first line of an http request formated with spaces "RequestType path?query version".
15+
* This is the first line of an http request formated with spaces "RequestMethod path?query version".
1616
*/
1717
public class HTTPRequestHeader {
1818
private static final int REQUIRED_REQUEST_ITEMS = 3;
1919
private final String rawRequest;
20-
private final String requestType;
20+
private final String requestMethod;
2121
private final String requestPath;
2222
private final Map<String, String> requestQuery;
2323
private final String httpVersion;
@@ -34,7 +34,7 @@ public HTTPRequestHeader(final String requestHeader) {
3434
if(tmp.length != REQUIRED_REQUEST_ITEMS) {
3535
throw new IllegalArgumentException("HTTPRequestHeader can only have 3 arguments! :"+requestHeader);
3636
}
37-
requestType = tmp[0].trim().toUpperCase();
37+
requestMethod = tmp[0].trim().toUpperCase();
3838
String ptmp = tmp[1].trim();
3939
int queryParamPos = ptmp.indexOf('?');
4040
if(queryParamPos >= 0) {
@@ -54,25 +54,28 @@ public HTTPRequestHeader(final String requestHeader) {
5454
/**
5555
* Creates a new Immutable {@link HTTPRequest} object from the parts that are in a request.
5656
*
57-
* @param requestType the {@link HTTPRequestType} to set.
58-
* @param requestPath the {@link HTTPRequestType} to set.
57+
* @param requestMethod the {@link HTTPRequestMethod} to set.
58+
* @param requestPath the {@link HTTPRequestMethod} to set.
5959
* @param requestQuery the query to set.
6060
* @param httpVersion the httpVersion to set.
6161
*/
62-
public HTTPRequestHeader(HTTPRequestType requestType, String requestPath, Map<String, String> requestQuery, String httpVersion){
63-
this(requestType.toString(), requestPath, requestQuery, httpVersion);
62+
public HTTPRequestHeader(HTTPRequestMethod requestMethod, String requestPath,
63+
Map<String, String> requestQuery, String httpVersion){
64+
this(requestMethod.toString(), requestPath, requestQuery, httpVersion);
6465
}
6566

6667
/**
67-
* Creates a new Immutable {@link HTTPRequest} object from the parts that are in a request. This can take non-standard RequestTypes
68+
* Creates a new Immutable {@link HTTPRequest} object from the parts that are in a request.
69+
* This can take non-standard request methods.
6870
*
69-
* @param requestType the {@link HTTPRequestType} to set.
70-
* @param requestPath the {@link HTTPRequestType} to set.
71+
* @param requestMethod the {@link HTTPRequestMethod} to set.
72+
* @param requestPath the {@link HTTPRequestMethod} to set.
7173
* @param requestQuery the query to set.
7274
* @param httpVersion the httpVersion to set.
7375
*/
74-
public HTTPRequestHeader(String requestType, String requestPath, Map<String, String> requestQuery, String httpVersion){
75-
this.requestType = requestType;
76+
public HTTPRequestHeader(String requestMethod, String requestPath,
77+
Map<String, String> requestQuery, String httpVersion){
78+
this.requestMethod = requestMethod;
7679
final LinkedHashMap<String, String> rqm = new LinkedHashMap<>();
7780
int queryParamPos = requestPath.indexOf("?");
7881
if(queryParamPos >= 0) {
@@ -89,12 +92,13 @@ public HTTPRequestHeader(String requestType, String requestPath, Map<String, Str
8992
} else {
9093
this.requestQuery = Collections.unmodifiableMap(rqm);
9194
}
92-
if(!HTTPConstants.HTTP_VERSION_1_1.equals(httpVersion) && !HTTPConstants.HTTP_VERSION_1_0.equals(httpVersion)) {
95+
if(!HTTPConstants.HTTP_VERSION_1_1.equals(httpVersion) &&
96+
!HTTPConstants.HTTP_VERSION_1_0.equals(httpVersion)) {
9397
throw new UnsupportedOperationException("Unknown HTTP Version!:"+httpVersion);
9498
}
9599
this.httpVersion = httpVersion.trim().toUpperCase();
96100
StringBuilder sb = new StringBuilder();
97-
sb.append(requestType.toString());
101+
sb.append(requestMethod.toString());
98102
sb.append(HTTPConstants.SPACE);
99103
sb.append(requestPath);
100104
if(requestQuery != null && ! requestQuery.isEmpty()) {
@@ -106,12 +110,12 @@ public HTTPRequestHeader(String requestType, String requestPath, Map<String, Str
106110
}
107111

108112
/**
109-
* Gets the requestType set in this request.
113+
* Gets the http request method (ie POST, GET, HEAD, etc).
110114
*
111-
* @return the request type.
115+
* @return the request method.
112116
*/
113-
public String getRequestType() { // TODO - rename to method?
114-
return requestType;
117+
public String getRequestMethod() {
118+
return requestMethod;
115119
}
116120

117121
/**

protocol/src/main/java/org/threadly/litesockets/protocols/http/response/HTTPResponseHeader.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public HTTPResponseHeader(final String responseHeader) {
2525
String[] tmp = rawResponse.split(" ", MAX_RESPONSE_ITEMS);
2626
try {
2727
httpVersion = tmp[0].trim();
28-
if(!httpVersion.equalsIgnoreCase(HTTPConstants.HTTP_VERSION_1_1) && !httpVersion.equalsIgnoreCase(HTTPConstants.HTTP_VERSION_1_0)) {
28+
if(!httpVersion.equalsIgnoreCase(HTTPConstants.HTTP_VERSION_1_1) &&
29+
!httpVersion.equalsIgnoreCase(HTTPConstants.HTTP_VERSION_1_0)) {
2930
throw new IllegalArgumentException("Unknown HTTP Version!:"+httpVersion);
3031
}
3132
hrc = HTTPResponseCode.findResponseCode(Integer.parseInt(tmp[1].trim()));
@@ -42,7 +43,8 @@ public HTTPResponseHeader(final String responseHeader) {
4243
* @throws IllegalArgumentException If the header fails to parse.
4344
*/
4445
public HTTPResponseHeader(final HTTPResponseCode rCode, final String httpVersion) {
45-
if(!httpVersion.equals(HTTPConstants.HTTP_VERSION_1_1) && !httpVersion.equals(HTTPConstants.HTTP_VERSION_1_0)) {
46+
if(!httpVersion.equals(HTTPConstants.HTTP_VERSION_1_1) &&
47+
!httpVersion.equals(HTTPConstants.HTTP_VERSION_1_0)) {
4648
throw new IllegalArgumentException("Unknown HTTP Version!:"+httpVersion);
4749
}
4850
hrc = rCode;

protocol/src/main/java/org/threadly/litesockets/protocols/http/shared/HTTPConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static enum PROTOCOL {
5959
new HTTPHeaders(HTTPConstants.DEFAULT_HEADERS_MAP);
6060

6161
public static final HTTPRequestHeader DEFAULT_REQUEST_HEADER =
62-
new HTTPRequestHeader(HTTPRequestType.GET, "/", null, HTTPConstants.HTTP_VERSION_1_1);
62+
new HTTPRequestHeader(HTTPRequestMethod.GET, "/", null, HTTPConstants.HTTP_VERSION_1_1);
6363

6464
public static final HTTPResponseHeader OK_RESPONSE_HEADER =
6565
new HTTPResponseHeader(HTTPResponseCode.OK, HTTPConstants.HTTP_VERSION_1_1);

protocol/src/main/java/org/threadly/litesockets/protocols/http/shared/HTTPRequestType.java renamed to protocol/src/main/java/org/threadly/litesockets/protocols/http/shared/HTTPRequestMethod.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.threadly.litesockets.protocols.http.shared;
22

33
/**
4-
* Enum of Http Request types.
4+
* Enum of Http Request methods.
55
*
66
* @author lwahlmeier
77
*
88
*/
9-
public enum HTTPRequestType {
9+
public enum HTTPRequestMethod {
1010
OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
1111
}

0 commit comments

Comments
 (0)