mirror of
https://github.com/SickGear/SickGear.git
synced 2024-11-25 22:35:05 +00:00
Merge branch 'feature/UpdateCacheControl' into dev
This commit is contained in:
commit
488feadc88
7 changed files with 17 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
### 3.32.0 (2024-xx-xx xx:xx:00 UTC)
|
### 3.32.0 (2024-xx-xx xx:xx:00 UTC)
|
||||||
|
|
||||||
|
* Update CacheControl 0.13.1 (783a338) to 0.14.0 (e2be0c2)
|
||||||
* Update idna library 3.4 (cab054c) to 3.7 (1d365e1)
|
* Update idna library 3.4 (cab054c) to 3.7 (1d365e1)
|
||||||
* Update Requests library 2.31.0 (8812812) to 2.32.3 (0e322af)
|
* Update Requests library 2.31.0 (8812812) to 2.32.3 (0e322af)
|
||||||
* Update urllib3 2.0.7 (56f01e0) to 2.2.1 (54d6edf)
|
* Update urllib3 2.0.7 (56f01e0) to 2.2.1 (54d6edf)
|
||||||
|
|
|
@ -8,7 +8,7 @@ Make it easy to import from cachecontrol without long namespaces.
|
||||||
"""
|
"""
|
||||||
__author__ = "Eric Larson"
|
__author__ = "Eric Larson"
|
||||||
__email__ = "eric@ionrock.org"
|
__email__ = "eric@ionrock.org"
|
||||||
__version__ = "0.13.1"
|
__version__ = "0.14.0"
|
||||||
|
|
||||||
from cachecontrol.adapter import CacheControlAdapter
|
from cachecontrol.adapter import CacheControlAdapter
|
||||||
from cachecontrol.controller import CacheController
|
from cachecontrol.controller import CacheController
|
||||||
|
|
|
@ -125,21 +125,21 @@ class CacheControlAdapter(HTTPAdapter):
|
||||||
else:
|
else:
|
||||||
# Wrap the response file with a wrapper that will cache the
|
# Wrap the response file with a wrapper that will cache the
|
||||||
# response when the stream has been consumed.
|
# response when the stream has been consumed.
|
||||||
response._fp = CallbackFileWrapper( # type: ignore[attr-defined]
|
response._fp = CallbackFileWrapper( # type: ignore[assignment]
|
||||||
response._fp, # type: ignore[attr-defined]
|
response._fp, # type: ignore[arg-type]
|
||||||
functools.partial(
|
functools.partial(
|
||||||
self.controller.cache_response, request, response
|
self.controller.cache_response, request, response
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if response.chunked:
|
if response.chunked:
|
||||||
super_update_chunk_length = response._update_chunk_length # type: ignore[attr-defined]
|
super_update_chunk_length = response._update_chunk_length
|
||||||
|
|
||||||
def _update_chunk_length(self: HTTPResponse) -> None:
|
def _update_chunk_length(self: HTTPResponse) -> None:
|
||||||
super_update_chunk_length()
|
super_update_chunk_length()
|
||||||
if self.chunk_left == 0:
|
if self.chunk_left == 0:
|
||||||
self._fp._close() # type: ignore[attr-defined]
|
self._fp._close() # type: ignore[union-attr]
|
||||||
|
|
||||||
response._update_chunk_length = types.MethodType( # type: ignore[attr-defined]
|
response._update_chunk_length = types.MethodType( # type: ignore[method-assign]
|
||||||
_update_chunk_length, response
|
_update_chunk_length, response
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class _FileCacheMixin:
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
directory: Union[str, Path],
|
directory: str | Path,
|
||||||
forever: bool = False,
|
forever: bool = False,
|
||||||
filemode: int = 0o0600,
|
filemode: int = 0o0600,
|
||||||
dirmode: int = 0o0700,
|
dirmode: int = 0o0700,
|
||||||
|
|
|
@ -142,6 +142,11 @@ class CacheController:
|
||||||
"""
|
"""
|
||||||
Load a cached response, or return None if it's not available.
|
Load a cached response, or return None if it's not available.
|
||||||
"""
|
"""
|
||||||
|
# We do not support caching of partial content: so if the request contains a
|
||||||
|
# Range header then we don't want to load anything from the cache.
|
||||||
|
if "Range" in request.headers:
|
||||||
|
return None
|
||||||
|
|
||||||
cache_url = request.url
|
cache_url = request.url
|
||||||
assert cache_url is not None
|
assert cache_url is not None
|
||||||
cache_data = self.cache.get(cache_url)
|
cache_data = self.cache.get(cache_url)
|
||||||
|
@ -480,7 +485,7 @@ class CacheController:
|
||||||
cached_response.headers.update(
|
cached_response.headers.update(
|
||||||
{
|
{
|
||||||
k: v
|
k: v
|
||||||
for k, v in response.headers.items() # type: ignore[no-untyped-call]
|
for k, v in response.headers.items()
|
||||||
if k.lower() not in excluded_headers
|
if k.lower() not in excluded_headers
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -68,7 +68,7 @@ class OneDayCache(BaseHeuristic):
|
||||||
|
|
||||||
if "expires" not in response.headers:
|
if "expires" not in response.headers:
|
||||||
date = parsedate(response.headers["date"])
|
date = parsedate(response.headers["date"])
|
||||||
expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[misc]
|
expires = expire_after(timedelta(days=1), date=datetime(*date[:6], tzinfo=timezone.utc)) # type: ignore[index,misc]
|
||||||
headers["expires"] = datetime_to_header(expires)
|
headers["expires"] = datetime_to_header(expires)
|
||||||
headers["cache-control"] = "public"
|
headers["cache-control"] = "public"
|
||||||
return headers
|
return headers
|
||||||
|
|
|
@ -32,13 +32,13 @@ class Serializer:
|
||||||
# also update the response with a new file handler to be
|
# also update the response with a new file handler to be
|
||||||
# sure it acts as though it was never read.
|
# sure it acts as though it was never read.
|
||||||
body = response.read(decode_content=False)
|
body = response.read(decode_content=False)
|
||||||
response._fp = io.BytesIO(body) # type: ignore[attr-defined]
|
response._fp = io.BytesIO(body) # type: ignore[assignment]
|
||||||
response.length_remaining = len(body)
|
response.length_remaining = len(body)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"response": {
|
"response": {
|
||||||
"body": body, # Empty bytestring if body is stored separately
|
"body": body, # Empty bytestring if body is stored separately
|
||||||
"headers": {str(k): str(v) for k, v in response.headers.items()}, # type: ignore[no-untyped-call]
|
"headers": {str(k): str(v) for k, v in response.headers.items()},
|
||||||
"status": response.status,
|
"status": response.status,
|
||||||
"version": response.version,
|
"version": response.version,
|
||||||
"reason": str(response.reason),
|
"reason": str(response.reason),
|
||||||
|
|
Loading…
Reference in a new issue