Merge pull request #2042 from mfietz/issue/2017-auto-download-file-type-error
Resolve file type errors
This commit is contained in:
commit
a2fc5a2b48
@ -208,7 +208,8 @@ public class DownloadService extends Service {
|
|||||||
boolean forbidden = status.getReason() == DownloadError.ERROR_FORBIDDEN
|
boolean forbidden = status.getReason() == DownloadError.ERROR_FORBIDDEN
|
||||||
&& String.valueOf(HttpURLConnection.HTTP_FORBIDDEN).equals(status.getReasonDetailed());
|
&& String.valueOf(HttpURLConnection.HTTP_FORBIDDEN).equals(status.getReasonDetailed());
|
||||||
boolean notEnoughSpace = status.getReason() == DownloadError.ERROR_NOT_ENOUGH_SPACE;
|
boolean notEnoughSpace = status.getReason() == DownloadError.ERROR_NOT_ENOUGH_SPACE;
|
||||||
if (httpNotFound || forbidden || notEnoughSpace) {
|
boolean wrongFileType = status.getReason() == DownloadError.ERROR_FILE_TYPE;
|
||||||
|
if (httpNotFound || forbidden || notEnoughSpace || wrongFileType) {
|
||||||
DBWriter.saveFeedItemAutoDownloadFailed(item).get();
|
DBWriter.saveFeedItemAutoDownloadFailed(item).get();
|
||||||
}
|
}
|
||||||
// to make lists reload the failed item, we fake an item update
|
// to make lists reload the failed item, we fake an item update
|
||||||
|
@ -182,10 +182,20 @@ public class HttpDownloader extends Downloader {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fail with a file type error when the content type is text and
|
||||||
|
// the reported content length is less than 100kb (or no length is given)
|
||||||
if(request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
if(request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
|
||||||
String contentType = response.header("Content-Type");
|
String contentType = response.header("Content-Type");
|
||||||
Log.d(TAG, "content type: " + contentType);
|
Log.d(TAG, "content type: " + contentType);
|
||||||
if(contentType.startsWith("text/")) {
|
int contentLength = -1;
|
||||||
|
String contentLen = response.header("Content-Length");
|
||||||
|
if(contentLen != null) {
|
||||||
|
try {
|
||||||
|
contentLength = Integer.parseInt(contentLen);
|
||||||
|
} catch(NumberFormatException e) {}
|
||||||
|
}
|
||||||
|
Log.d(TAG, "content length: " + contentLength);
|
||||||
|
if(contentType.startsWith("text/") && contentLength < 100 * 1024) {
|
||||||
onFail(DownloadError.ERROR_FILE_TYPE, null);
|
onFail(DownloadError.ERROR_FILE_TYPE, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user