Skip to content

Commit aaefc6c

Browse files
committed
Track response body support for HttpOpener.Method. (#463)
1 parent e5f5753 commit aaefc6c

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

metafacture-io/src/main/java/org/metafacture/io/HttpOpener.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,38 @@ public final class HttpOpener extends DefaultObjectPipe<String, ObjectReceiver<R
7373

7474
public enum Method {
7575

76-
DELETE(false),
77-
GET(false),
78-
HEAD(false),
79-
OPTIONS(false),
80-
POST(true),
81-
PUT(true),
82-
TRACE(false);
83-
84-
private final boolean inputAsBody;
85-
86-
Method(final boolean inputAsBody) {
87-
this.inputAsBody = inputAsBody;
76+
DELETE(false, true),
77+
GET(false, true),
78+
HEAD(false, false),
79+
OPTIONS(false, true),
80+
POST(true, true),
81+
PUT(true, true),
82+
TRACE(false, true);
83+
84+
private final boolean requestHasBody;
85+
private final boolean responseHasBody;
86+
87+
Method(final boolean requestHasBody, final boolean responseHasBody) {
88+
this.requestHasBody = requestHasBody;
89+
this.responseHasBody = responseHasBody;
8890
}
8991

90-
private boolean getInputAsBody() {
91-
return inputAsBody;
92+
/**
93+
* Checks whether the request method accepts a request body.
94+
*
95+
* @return true if the request method accepts a request body
96+
*/
97+
public boolean getRequestHasBody() {
98+
return requestHasBody;
99+
}
100+
101+
/**
102+
* Checks whether the request method returns a response body.
103+
*
104+
* @return true if the request method returns a response body
105+
*/
106+
public boolean getResponseHasBody() {
107+
return responseHasBody;
92108
}
93109

94110
}
@@ -207,7 +223,7 @@ public void process(final String input) {
207223
try {
208224
final String requestUrl = getInput(input, url);
209225
final String requestBody = getInput(input,
210-
body == null && method.getInputAsBody() ? INPUT_DESIGNATOR : body);
226+
body == null && method.getRequestHasBody() ? INPUT_DESIGNATOR : body);
211227

212228
final HttpURLConnection connection =
213229
(HttpURLConnection) new URL(requestUrl).openConnection();

0 commit comments

Comments
 (0)