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;
}
Aggregations