diff options
Diffstat (limited to 'src/main/java/com/android/volley/toolbox/HurlStack.java')
-rw-r--r-- | src/main/java/com/android/volley/toolbox/HurlStack.java | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/main/java/com/android/volley/toolbox/HurlStack.java b/src/main/java/com/android/volley/toolbox/HurlStack.java index c53d5e0..66f441d 100644 --- a/src/main/java/com/android/volley/toolbox/HurlStack.java +++ b/src/main/java/com/android/volley/toolbox/HurlStack.java @@ -59,7 +59,7 @@ public class HurlStack implements HttpStack { * Returns a URL to use instead of the provided one, or null to indicate * this URL should not be used at all. */ - public String rewriteUrl(String originalUrl); + String rewriteUrl(String originalUrl); } private final UrlRewriter mUrlRewriter; @@ -209,16 +209,8 @@ public class HurlStack implements HttpStack { // GET. Otherwise, it is assumed that the request is a POST. byte[] postBody = request.getPostBody(); if (postBody != 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. - connection.setDoOutput(true); connection.setRequestMethod("POST"); - connection.addRequestProperty(HEADER_CONTENT_TYPE, - request.getPostBodyContentType()); - DataOutputStream out = new DataOutputStream(connection.getOutputStream()); - out.write(postBody); - out.close(); + addBody(connection, request, postBody); } break; case Method.GET: @@ -259,11 +251,19 @@ public class HurlStack implements HttpStack { throws IOException, AuthFailureError { byte[] body = request.getBody(); if (body != null) { - connection.setDoOutput(true); - connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType()); - DataOutputStream out = new DataOutputStream(connection.getOutputStream()); - out.write(body); - out.close(); + addBody(connection, request, body); } } + + private static void addBody(HttpURLConnection connection, Request<?> request, byte[] body) + throws IOException, AuthFailureError { + // 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. + connection.setDoOutput(true); + connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType()); + DataOutputStream out = new DataOutputStream(connection.getOutputStream()); + out.write(body); + out.close(); + } } |