Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: Revert mandatory `Content-Length`

NTFSvolume24c372bd531d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73e6f4be6..3fb4a9e48 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Detect and report BasedFlare anti-bot protection
- Limit max queued downloads of a single site to the config concurrency limit x10 (capped at 50). All scraping for a site will be paused if its queue is full
- Always remove generated id from filenames (Cyberdrop)
+- Revert mandatory `Content-Length` header introduced in v9.15.0
The following options, which were CLI only arguments, now have dedicated config entries:
diff --git a/cyberdrop_dl/clients/downloads.py b/cyberdrop_dl/clients/downloads.py
index 29a181a6c..da7253bbb 100644
--- a/cyberdrop_dl/clients/downloads.py
+++ b/cyberdrop_dl/clients/downloads.py
@@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Any, final
from aiohttp import hdrs
-from cyberdrop_dl import aio, constants, env, ffmpeg, storage
+from cyberdrop_dl import aio, constants, ffmpeg, storage
from cyberdrop_dl.clients import etag
from cyberdrop_dl.constants import FileExt, HashMode
from cyberdrop_dl.exceptions import DownloadError, InvalidContentTypeError, SlowDownloadError
@@ -486,7 +486,6 @@ def _get_content_length(headers: Mapping[str, str]) -> int:
try:
return int(headers[hdrs.CONTENT_LENGTH])
except KeyError:
- if env.ALLOW_MISSING_CONTENT_LENGTH:
- return 0
+ return 0
msg = f"Download response has no `{hdrs.CONTENT_LENGTH}` header. Refusing to download"
raise DownloadError(HTTPStatus.LENGTH_REQUIRED, msg, retry=False) from None
diff --git a/cyberdrop_dl/env.py b/cyberdrop_dl/env.py
index b816f0315..5906f9a82 100644
--- a/cyberdrop_dl/env.py
+++ b/cyberdrop_dl/env.py
@@ -19,7 +19,7 @@ RUNNING_IN_TERMUX = bool(
)
FORCE_PORTRAIT_MODE = bool(_env("PORTRAIT_MODE") or RUNNING_IN_TERMUX)
-ALLOW_MISSING_CONTENT_LENGTH = bool(_env("ALLOW_MISSING_CONTENT_LENGTH"))
+
DEBUG_LOG_FOLDER = _env("DEBUG_LOG_FOLDER")
MAX_CRAWLER_ERRORS = int(_env("MAX_CRAWLER_ERRORS") or 10)
diff --git a/tests/test_downloader.py b/tests/test_downloader.py
index 705f24910..ab28ee094 100644
--- a/tests/test_downloader.py
+++ b/tests/test_downloader.py
@@ -1,16 +1,13 @@
from __future__ import annotations
-from http import HTTPStatus
from pathlib import Path
from typing import TYPE_CHECKING
from unittest import mock
import pytest
-from cyberdrop_dl import env
from cyberdrop_dl.clients.downloads import _get_content_length, filter_by_duration
from cyberdrop_dl.downloader.http import Downloader
-from cyberdrop_dl.exceptions import DownloadError
from cyberdrop_dl.url_objects import AbsoluteHttpURL, MediaItem
if TYPE_CHECKING:
@@ -60,17 +57,5 @@ async def test_probe_duration_is_skipped_on_default_config(manager: Manager) ->
def test_missing_content_lenght() -> None:
-
assert _get_content_length({"Content-Length": "200"}) == 200
-
- with pytest.raises(DownloadError) as exc:
- _get_content_length({})
-
- assert exc.value.status is HTTPStatus.LENGTH_REQUIRED
- assert exc.value.retry is False
-
- env.ALLOW_MISSING_CONTENT_LENGTH, old_value = True, env.ALLOW_MISSING_CONTENT_LENGTH
- try:
- assert _get_content_length({}) == 0
- finally:
- env.ALLOW_MISSING_CONTENT_LENGTH = old_value
+ assert _get_content_length({}) == 0