Edits after code review
@@ -130,11 +130,10 @@ public class HurlStack implements HttpStack {
/**
* Checks if a response message contains a body.
- *
+ * @see <a href="https://tools.ietf.org/html/rfc7230#section-3.3">RFC 7230 section 3.3</a>
* @param requestMethod request method
* @param responseCode response status code
* @return whether the response has a body
- * @see <a href="https://tools.ietf.org/html/rfc7230#section-3.3">RFC 7230 section 3.3</a>
*/
private static boolean hasResponseBody(int requestMethod, int responseCode) {
return requestMethod != Request.Method.HEAD
@@ -145,7 +144,6 @@ public class HurlStack implements HttpStack {
/**
* Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
- *
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.
*/
@@ -180,7 +178,6 @@ public class HurlStack implements HttpStack {
/**
* Opens an {@link HttpURLConnection} with parameters.
- *
* @param url
* @return an open connection
* @throws IOException
@@ -212,8 +209,9 @@ public class HurlStack implements HttpStack {
// GET. Otherwise, it is assumed that the request is a POST.
byte[] postBody = request.getPostBody();
if (postBody != null) {
+ connection.setDoOutput(true);
connection.setRequestMethod("POST");
- addBodyIfExists(connection, request, postBody);
+ addBody(connection, request, postBody);
}
break;
case Method.GET:
@@ -254,13 +252,12 @@ public class HurlStack implements HttpStack {
throws IOException, AuthFailureError {
byte[] body = request.getBody();
if (body != null) {
- addBodyIfExists(connection, request, body);
+ addBody(connection, request, body);
}
}
- private static void addBodyIfExists(HttpURLConnection connection, Request<?> request, byte[] body)
+ private static void addBody(HttpURLConnection connection, Request<?> request, byte[] body)
throws IOException, AuthFailureError {
- if (body != null) {
// Prepare output. There is no need to set Content-Length explicitly,
// since this is handled by HttpURLConnection using the size of the prepared
// output stream.
@@ -271,4 +268,3 @@ public class HurlStack implements HttpStack {
out.close();
}
}
\ No newline at end of file
-}
