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
|
||||
&& 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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue