lingochamp/FileDownloader · error · FileDownloadGiveUpRetryException

can't know the size of the download file, and its…

Error message

can't know the size of the download file, and its Transfer-Encoding is not Chunked either.
you can ignore such exception by add http.lenient=true to the filedownloader.properties

What it means

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.

Solutions

  1. Add 'http.lenient=true' to filedownloader.properties so such responses are handled as chunked resources.
  2. Fix the server/CDN to send a correct Content-Length header for the file.
  3. Ensure no proxy/gateway is stripping or corrupting Content-Length (disable response buffering/compression for that endpoint).
  4. If you control the request, prefer endpoints serving static files with known size.

Example fix

// before: filedownloader.properties
# (no lenient setting)

// after: filedownloader.properties
http.lenient=true
Defensive patterns

Strategy: fallback

Validate before calling

// Before starting a task against a suspect endpoint:
HttpURLConnection c = (HttpURLConnection) new URL(url).openConnection();
String len = c.getHeaderField("Content-Length");
String te = c.getHeaderField("Transfer-Encoding");
boolean ok = (len != null && !len.isEmpty()) || "chunked".equalsIgnoreCase(te);

Try / catch

try {
    downloader.create(url).setPath(path).start();
} catch (FileDownloadGiveUpRetryException e) {
    // fall back to manual streaming download that tolerates unknown length
}

Prevention

When it happens

Trigger: 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.

Common situations: Downloading from servers/CDNs that strip Content-Length; responses passed through compression or gzip proxies; APIs returning streamed bodies instead of static files.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of lingochamp/FileDownloader@6237a8cac1 (2026-09-08). Data as JSON: /api/errors/37087deedde73c75. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/liulishuo/filedownloader/util/FileDownloadUtils.java:621

        final String transferEncoding = connection.getResponseHeaderField("Transfer-Encoding");

        if (contentLength < 0) {
            final boolean isEncodingChunked = transferEncoding != null && transferEncoding
                    .equals("chunked");
            if (!isEncodingChunked) {
                // not chunked transfer encoding data
                if (FileDownloadProperties.getImpl().httpLenient) {
                    // do not response content-length either not chunk transfer encoding,
                    // but HTTP lenient is true, so handle as the case of transfer encoding chunk
                    contentLength = TOTAL_VALUE_IN_CHUNKED_RESOURCE;
                    if (FileDownloadLog.NEED_LOG) {
                        FileDownloadLog
                                .d(FileDownloadUtils.class, "%d response header is not legal but "
                                        + "HTTP lenient is true, so handle as the case of "
                                        + "transfer encoding chunk", id);
                    }
                } else {
                    throw new FileDownloadGiveUpRetryException("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");
                }
            } else {
                contentLength = TOTAL_VALUE_IN_CHUNKED_RESOURCE;
            }
        }

        return contentLength;
    }

    public static long findContentLengthFromContentRange(FileDownloadConnection connection) {
        final String contentRange = getContentRangeHeader(connection);
        long contentLength = parseContentLengthFromContentRange(contentRange);
        if (contentLength < 0) contentLength = TOTAL_VALUE_IN_CHUNKED_RESOURCE;
        return contentLength;
    }

View on GitHub (pinned to 6237a8cac1)