Search in sources :

Example 1 with DefaultHttpRedirectHandler

use of com.lidroid.xutils.http.callback.DefaultHttpRedirectHandler in project xUtils by wyouflf.

the class SyncHttpHandler method handleResponse.

private ResponseStream handleResponse(HttpResponse response) throws HttpException, IOException {
    if (response == null) {
        throw new HttpException("response is null");
    }
    StatusLine status = response.getStatusLine();
    int statusCode = status.getStatusCode();
    if (statusCode < 300) {
        ResponseStream responseStream = new ResponseStream(response, charset, requestUrl, expiry);
        responseStream.setRequestMethod(requestMethod);
        return responseStream;
    } else if (statusCode == 301 || statusCode == 302) {
        if (httpRedirectHandler == null) {
            httpRedirectHandler = new DefaultHttpRedirectHandler();
        }
        HttpRequestBase request = httpRedirectHandler.getDirectRequest(response);
        if (request != null) {
            return this.sendRequest(request);
        }
    } else if (statusCode == 416) {
        throw new HttpException(statusCode, "maybe the file has downloaded completely");
    } else {
        throw new HttpException(statusCode, status.getReasonPhrase());
    }
    return null;
}
Also used : StatusLine(org.apache.http.StatusLine) DefaultHttpRedirectHandler(com.lidroid.xutils.http.callback.DefaultHttpRedirectHandler) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpException(com.lidroid.xutils.exception.HttpException)

Aggregations

HttpException (com.lidroid.xutils.exception.HttpException)1 DefaultHttpRedirectHandler (com.lidroid.xutils.http.callback.DefaultHttpRedirectHandler)1 StatusLine (org.apache.http.StatusLine)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1