fix(downloader): correct resume progress and avoid httpx private API

Two bugs found by code review:

1. Progress bar exceeds 100% on resumed downloads because
   Content-Length from a Range response covers only remaining
   bytes. Now adds resume_from for the true total.

2. session.transport reached into httpx.Client._transport, a
   private attribute that may break on httpx upgrades. Transport
   is now stored at construction time instead.
This commit is contained in:
AlexKucera committed 2026-06-06 09:28:33 +02:00
1 parent 2466ef5fa8
commit 8acea390e6
4 files changed
+21 -5

No files matched your search

+8 -3
View File
@@ -47,6 +47,7 @@ class LibroFmSession:
self._timeout = timeout
self._access_token: str | None = None
self._api_semaphore = threading.Semaphore(API_SEMAPHORE_CAPACITY)
self._transport = transport
self._client = httpx.Client(
base_url=self._base_url,
@@ -56,9 +57,13 @@ class LibroFmSession:
)
@property
def transport(self) -> httpx.BaseTransport:
"""Return the underlying httpx transport for streaming downloads."""
return self._client._transport
def transport(self) -> httpx.BaseTransport | None:
"""Return the httpx transport for streaming downloads.
Stored at construction time to avoid reaching into
``httpx.Client._transport``, which is private API.
"""
return self._transport
def authenticate(self) -> str:
"""OAuth2 password grant → returns access_token.