diff options
author | Maurice Chu <mochu@google.com> | 2013-11-12 12:08:03 -0800 |
---|---|---|
committer | Maurice Chu <mochu@google.com> | 2013-12-19 17:44:01 +0000 |
commit | 364614be46d20fba35c3b6bc1c2d43fe8e861e9c (patch) | |
tree | ea403a5ee0f28eb56c7d4ba840b405a3c9f4c17f /src | |
parent | 379c1aec119acef172452b17dca481cedb86ba0f (diff) | |
download | volley-364614be46d20fba35c3b6bc1c2d43fe8e861e9c.tar.gz |
Revert "Revert "Add in additional http request types""
This reverts commit 9e5c44f22b47fcb0d37c7b10de3b5db542424fa5.
Also, to run tests, the android:targetPackage in the
<instrumentation>needs to be set to
com.android.volley.tests (i.e., the volley_tests apk itself) because
volley is just a jar that is statically linked into the test apk.
Change-Id: I41ad41e401084b79fbf9712e24d7f7fdeb358223
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/volley/Request.java | 9 | ||||
-rw-r--r-- | src/com/android/volley/toolbox/HttpClientStack.java | 47 | ||||
-rw-r--r-- | src/com/android/volley/toolbox/HurlStack.java | 13 |
3 files changed, 68 insertions, 1 deletions
diff --git a/src/com/android/volley/Request.java b/src/com/android/volley/Request.java index 9fee0a0..28fb5f9 100644 --- a/src/com/android/volley/Request.java +++ b/src/com/android/volley/Request.java @@ -51,12 +51,19 @@ public abstract class Request<T> implements Comparable<Request<T>> { int POST = 1; int PUT = 2; int DELETE = 3; + int HEAD = 4; + int OPTIONS = 5; + int TRACE = 6; + int PATCH = 7; } /** An event log tracing the lifetime of this request; for debugging. */ private final MarkerLog mEventLog = MarkerLog.ENABLED ? new MarkerLog() : null; - /** Request method of this request. Currently supports GET, POST, PUT, and DELETE. */ + /** + * Request method of this request. Currently supports GET, POST, PUT, DELETE, HEAD, OPTIONS, + * TRACE, and PATCH. + */ private final int mMethod; /** URL of this request. */ diff --git a/src/com/android/volley/toolbox/HttpClientStack.java b/src/com/android/volley/toolbox/HttpClientStack.java index f8dfdab..377110e 100644 --- a/src/com/android/volley/toolbox/HttpClientStack.java +++ b/src/com/android/volley/toolbox/HttpClientStack.java @@ -27,8 +27,11 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.client.methods.HttpOptions; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpTrace; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.message.BasicNameValuePair; @@ -36,6 +39,7 @@ import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import java.io.IOException; +import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -122,6 +126,18 @@ public class HttpClientStack implements HttpStack { setEntityIfNonEmptyBody(putRequest, request); return putRequest; } + case Method.HEAD: + return new HttpHead(request.getUrl()); + case Method.OPTIONS: + return new HttpOptions(request.getUrl()); + case Method.TRACE: + return new HttpTrace(request.getUrl()); + case Method.PATCH: { + HttpPatch patchRequest = new HttpPatch(request.getUrl()); + patchRequest.addHeader(HEADER_CONTENT_TYPE, request.getBodyContentType()); + setEntityIfNonEmptyBody(patchRequest, request); + return patchRequest; + } default: throw new IllegalStateException("Unknown request method."); } @@ -144,4 +160,35 @@ public class HttpClientStack implements HttpStack { protected void onPrepareRequest(HttpUriRequest request) throws IOException { // Nothing. } + + /** + * The HttpPatch class does not exist in the Android framework, so this has been defined here. + */ + public static final class HttpPatch extends HttpEntityEnclosingRequestBase { + + public final static String METHOD_NAME = "PATCH"; + + public HttpPatch() { + super(); + } + + public HttpPatch(final URI uri) { + super(); + setURI(uri); + } + + /** + * @throws IllegalArgumentException if the uri is invalid. + */ + public HttpPatch(final String uri) { + super(); + setURI(URI.create(uri)); + } + + @Override + public String getMethod() { + return METHOD_NAME; + } + + } } diff --git a/src/com/android/volley/toolbox/HurlStack.java b/src/com/android/volley/toolbox/HurlStack.java index 97f94f0..49bdf6a 100644 --- a/src/com/android/volley/toolbox/HurlStack.java +++ b/src/com/android/volley/toolbox/HurlStack.java @@ -213,6 +213,19 @@ public class HurlStack implements HttpStack { connection.setRequestMethod("PUT"); addBodyIfExists(connection, request); break; + case Method.HEAD: + connection.setRequestMethod("HEAD"); + break; + case Method.OPTIONS: + connection.setRequestMethod("OPTIONS"); + break; + case Method.TRACE: + connection.setRequestMethod("TRACE"); + break; + case Method.PATCH: + addBodyIfExists(connection, request); + connection.setRequestMethod("PATCH"); + break; default: throw new IllegalStateException("Unknown method type."); } |