Merge pull request #2042 from mfietz/issue/2017-auto-download-file-type-error

Resolve file type errors
This commit is contained in:
Martin Fietz 2016-06-24 11:43:29 +02:00 committed by GitHub
commit a2fc5a2b48
2 changed files with 13 additions and 2 deletions

View File

@ -208,7 +208,8 @@ public class DownloadService extends Service {
boolean forbidden = status.getReason() == DownloadError.ERROR_FORBIDDEN
&& String.valueOf(HttpURLConnection.HTTP_FORBIDDEN).equals(status.getReasonDetailed());
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();
}
// to make lists reload the failed item, we fake an item update

View File

@ -182,10 +182,20 @@ public class HttpDownloader extends Downloader {
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) {
String contentType = response.header("Content-Type");
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);
return;
}