Skip to content

Commit 47c849b

Browse files
committed
Added HEAD request support, Closes android-async-http#307, Fixes android-async-http#146
1 parent 4062411 commit 47c849b

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

library/src/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.http.client.methods.HttpDelete;
3636
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
3737
import org.apache.http.client.methods.HttpGet;
38+
import org.apache.http.client.methods.HttpHead;
3839
import org.apache.http.client.methods.HttpPost;
3940
import org.apache.http.client.methods.HttpPut;
4041
import org.apache.http.client.methods.HttpUriRequest;
@@ -302,6 +303,67 @@ public void cancelRequests(Context context, boolean mayInterruptIfRunning) {
302303
requestMap.remove(context);
303304
}
304305

306+
//
307+
// HTTP HEAD Requests
308+
//
309+
310+
/**
311+
* Perform a HTTP HEAD request, without any parameters.
312+
* @param url the URL to send the request to.
313+
* @param responseHandler the response handler instance that should handle the response.
314+
*/
315+
public void head(String url, AsyncHttpResponseHandler responseHandler) {
316+
head(null, url, null, responseHandler);
317+
}
318+
319+
/**
320+
* Perform a HTTP HEAD request with parameters.
321+
* @param url the URL to send the request to.
322+
* @param params additional HEAD parameters to send with the request.
323+
* @param responseHandler the response handler instance that should handle the response.
324+
*/
325+
public void head(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
326+
head(null, url, params, responseHandler);
327+
}
328+
329+
/**
330+
* Perform a HTTP HEAD request without any parameters and track the Android Context which initiated the request.
331+
* @param context the Android Context which initiated the request.
332+
* @param url the URL to send the request to.
333+
* @param responseHandler the response handler instance that should handle the response.
334+
*/
335+
public void head(Context context, String url, AsyncHttpResponseHandler responseHandler) {
336+
head(context, url, null, responseHandler);
337+
}
338+
339+
/**
340+
* Perform a HTTP HEAD request and track the Android Context which initiated the request.
341+
* @param context the Android Context which initiated the request.
342+
* @param url the URL to send the request to.
343+
* @param params additional HEAD parameters to send with the request.
344+
* @param responseHandler the response handler instance that should handle the response.
345+
*/
346+
public void head(Context context, String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
347+
sendRequest(httpClient, httpContext, new HttpHead(getUrlWithQueryString(url, params)), null, responseHandler, context);
348+
}
349+
350+
/**
351+
* Perform a HTTP HEAD request and track the Android Context which initiated
352+
* the request with customized headers
353+
*
354+
* @param url the URL to send the request to.
355+
* @param headers set headers only for this request
356+
* @param params additional HEAD parameters to send with the request.
357+
* @param responseHandler the response handler instance that should handle
358+
* the response.
359+
*/
360+
public void head(Context context, String url, Header[] headers, RequestParams params, AsyncHttpResponseHandler responseHandler) {
361+
HttpUriRequest request = new HttpHead(getUrlWithQueryString(url, params));
362+
if(headers != null) request.setHeaders(headers);
363+
sendRequest(httpClient, httpContext, request, null, responseHandler,
364+
context);
365+
}
366+
305367

306368
//
307369
// HTTP GET Requests

library/src/com/loopj/android/http/BinaryHttpResponseHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected void handleMessage(Message msg) {
147147
switch (msg.what) {
148148
case SUCCESS_MESSAGE:
149149
response = (Object[]) msg.obj;
150-
handleSuccessMessage(((Integer) response[0]).intValue(), (byte[]) response[1]);
150+
handleSuccessMessage((Integer) response[0], (byte[]) response[1]);
151151
break;
152152
case FAILURE_MESSAGE:
153153
response = (Object[]) msg.obj;

0 commit comments

Comments
 (0)