{"record":{"id":"37087deedde73c75","repo":"lingochamp/FileDownloader","slug":"can-t-know-the-size-of-the-download-file-and-its","errorCode":null,"errorMessage":"can't know the size of the download file, and its Transfer-Encoding is not Chunked either.\nyou can ignore such exception by add http.lenient=true to the filedownloader.properties","messagePattern":"can't know the size of the download file, and its Transfer-Encoding is not Chunked either\\.\nyou can ignore such exception by add http\\.lenient=true to the filedownloader\\.properties","errorType":"exception","errorClass":"FileDownloadGiveUpRetryException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/util/FileDownloadUtils.java","lineNumber":621,"sourceCode":"        final String transferEncoding = connection.getResponseHeaderField(\"Transfer-Encoding\");\n\n        if (contentLength < 0) {\n            final boolean isEncodingChunked = transferEncoding != null && transferEncoding\n                    .equals(\"chunked\");\n            if (!isEncodingChunked) {\n                // not chunked transfer encoding data\n                if (FileDownloadProperties.getImpl().httpLenient) {\n                    // do not response content-length either not chunk transfer encoding,\n                    // but HTTP lenient is true, so handle as the case of transfer encoding chunk\n                    contentLength = TOTAL_VALUE_IN_CHUNKED_RESOURCE;\n                    if (FileDownloadLog.NEED_LOG) {\n                        FileDownloadLog\n                                .d(FileDownloadUtils.class, \"%d response header is not legal but \"\n                                        + \"HTTP lenient is true, so handle as the case of \"\n                                        + \"transfer encoding chunk\", id);\n                    }\n                } else {\n                    throw new FileDownloadGiveUpRetryException(\"can't know the size of the \"\n                            + \"download file, and its Transfer-Encoding is not Chunked \"\n                            + \"either.\\nyou can ignore such exception by add \"\n                            + \"http.lenient=true to the filedownloader.properties\");\n                }\n            } else {\n                contentLength = TOTAL_VALUE_IN_CHUNKED_RESOURCE;\n            }\n        }\n\n        return contentLength;\n    }\n\n    public static long findContentLengthFromContentRange(FileDownloadConnection connection) {\n        final String contentRange = getContentRangeHeader(connection);\n        long contentLength = parseContentLengthFromContentRange(contentRange);\n        if (contentLength < 0) contentLength = TOTAL_VALUE_IN_CHUNKED_RESOURCE;\n        return contentLength;\n    }","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/util/FileDownloadUtils.java#L603-L639","documentation":"findContentLength determines the total size of the download from the Content-Length header. If the header is absent/invalid AND Transfer-Encoding is not 'chunked', the library cannot track progress or validate the download, so it throws FileDownloadGiveUpRetryException (no retry will help). The message tells you how to opt into lenient handling of such responses.","triggerScenarios":"A server responds 200/206 without a parsable Content-Length and without Transfer-Encoding: chunked, e.g. streamed responses, misconfigured proxies/CDNs, or dynamic-generated content.","commonSituations":"Downloading from servers/CDNs that strip Content-Length; responses passed through compression or gzip proxies; APIs returning streamed bodies instead of static files.","solutions":["Add 'http.lenient=true' to filedownloader.properties so such responses are handled as chunked resources.","Fix the server/CDN to send a correct Content-Length header for the file.","Ensure no proxy/gateway is stripping or corrupting Content-Length (disable response buffering/compression for that endpoint).","If you control the request, prefer endpoints serving static files with known size."],"exampleFix":"// before: filedownloader.properties\n# (no lenient setting)\n\n// after: filedownloader.properties\nhttp.lenient=true","handlingStrategy":"fallback","validationCode":"// Before starting a task against a suspect endpoint:\nHttpURLConnection c = (HttpURLConnection) new URL(url).openConnection();\nString len = c.getHeaderField(\"Content-Length\");\nString te = c.getHeaderField(\"Transfer-Encoding\");\nboolean ok = (len != null && !len.isEmpty()) || \"chunked\".equalsIgnoreCase(te);","typeGuard":null,"tryCatchPattern":"try {\n    downloader.create(url).setPath(path).start();\n} catch (FileDownloadGiveUpRetryException e) {\n    // fall back to manual streaming download that tolerates unknown length\n}","preventionTips":["Set http.lenient=true in filedownloader.properties if you download from servers without Content-Length.","Probe endpoints once with a HEAD request to confirm Content-Length exists.","Bypass proxies/CDNs that strip Content-Length for download endpoints."],"tags":["android","http","content-length","chunked","filedownloader"],"backgroundTag":"http-error-response","analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}