summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2023-05-15 14:48:09 -0500
committerGitHub <noreply@github.com>2023-05-15 14:48:09 -0500
commit68760791753c0b7892a669028b3b7658eb80220b (patch)
tree4eafec3191f8d4b80814dae94e833052d21cf2e7
parent6a59bfd6273112e9aca59e9588fd71edbafb8df3 (diff)
parentff2f693e0c6f0f6112ac8b158bdc9b1926a66b4a (diff)
downloadrequests-cache-main.tar.gz
Merge pull request #826 from requests-cache/urllib3-2.0HEADmain
Add compatibility with urllib3 2.0
-rw-r--r--.pre-commit-config.yaml4
-rw-r--r--HISTORY.md1
-rw-r--r--poetry.lock88
-rw-r--r--requests_cache/models/raw_response.py31
-rw-r--r--tests/integration/base_cache_test.py13
-rw-r--r--tests/unit/models/test_raw_response.py1
6 files changed, 71 insertions, 67 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 998da61..d9e48c2 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -17,11 +17,11 @@ repos:
hooks:
- id: isort
- repo: https://github.com/charliermarsh/ruff-pre-commit
- rev: v0.0.265
+ rev: v0.0.267
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
- rev: v1.2.0
+ rev: v1.3.0
hooks:
- id: mypy
files: requests_cache
diff --git a/HISTORY.md b/HISTORY.md
index 0f703a6..a916dc7 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -6,6 +6,7 @@
## 1.0.2 (2023-TBD)
* Revert normalizing `CachedResponse.url` so it matches the original request URL
* Fix loading cached JSON content when `decode_content=True` and the root element is a list
+* Add compatibility with urllib3 2.0
## 1.0.1 (2023-03-24)
* Ignore `Cache-Control: must-revalidate` and `no-cache` response headers with `cache_control=False`
diff --git a/poetry.lock b/poetry.lock
index aa5ffca..9b7e514 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -50,7 +50,7 @@ tests = ["attrs[tests-no-zope]", "zope-interface"]
tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"]
[[package]]
-name = "babel"
+name = "Babel"
version = "2.12.1"
description = "Internationalization utilities"
category = "main"
@@ -77,14 +77,14 @@ lxml = ["lxml"]
[[package]]
name = "boto3"
-version = "1.26.129"
+version = "1.26.133"
description = "The AWS SDK for Python"
category = "main"
optional = true
python-versions = ">= 3.7"
[package.dependencies]
-botocore = ">=1.29.129,<1.30.0"
+botocore = ">=1.29.133,<1.30.0"
jmespath = ">=0.7.1,<2.0.0"
s3transfer = ">=0.6.0,<0.7.0"
@@ -93,7 +93,7 @@ crt = ["botocore[crt] (>=1.21.0,<2.0a0)"]
[[package]]
name = "botocore"
-version = "1.29.129"
+version = "1.29.133"
description = "Low-level, data-driven core of boto 3."
category = "main"
optional = true
@@ -364,7 +364,7 @@ optional = true
python-versions = ">=3.7"
[[package]]
-name = "jinja2"
+name = "Jinja2"
version = "3.1.2"
description = "A very fast and expressive template engine."
category = "main"
@@ -439,7 +439,7 @@ typing_extensions = {version = ">=3.7.4", markers = "python_version < \"3.8\""}
[package.extras]
benchmarking = ["psutil", "pytest", "pytest-benchmark"]
-code-style = ["pre-commit (>=3.0,<4.0)"]
+code_style = ["pre-commit (>=3.0,<4.0)"]
compare = ["commonmark (>=0.9,<1.0)", "markdown (>=3.4,<4.0)", "mistletoe (>=1.0,<2.0)", "mistune (>=2.0,<3.0)", "panflute (>=2.3,<3.0)"]
linkify = ["linkify-it-py (>=1,<3)"]
plugins = ["mdit-py-plugins"]
@@ -448,7 +448,7 @@ rtd = ["attrs", "myst-parser", "pyyaml", "sphinx", "sphinx-copybutton", "sphinx-
testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"]
[[package]]
-name = "markupsafe"
+name = "MarkupSafe"
version = "2.1.2"
description = "Safely add untrusted strings to HTML/XML markup."
category = "main"
@@ -486,7 +486,7 @@ python-versions = ">=3.7"
markdown-it-py = ">=1.0.0,<3.0.0"
[package.extras]
-code-style = ["pre-commit"]
+code_style = ["pre-commit"]
rtd = ["attrs", "myst-parser (>=0.16.1,<0.17.0)", "sphinx-book-theme (>=0.1.0,<0.2.0)"]
testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"]
@@ -516,7 +516,7 @@ sphinx = ">=5,<7"
typing-extensions = {version = "*", markers = "python_version < \"3.8\""}
[package.extras]
-code-style = ["pre-commit (>=3.0,<4.0)"]
+code_style = ["pre-commit (>=3.0,<4.0)"]
linkify = ["linkify-it-py (>=1.0,<2.0)"]
rtd = ["ipython", "pydata-sphinx-theme (==v0.13.0rc4)", "sphinx-autodoc2 (>=0.4.2,<0.5.0)", "sphinx-book-theme (==1.0.0rc2)", "sphinx-copybutton", "sphinx-design2", "sphinx-pyscript", "sphinx-tippy (>=0.3.1)", "sphinx-togglebutton", "sphinxext-opengraph (>=0.7.5,<0.8.0)", "sphinxext-rediraffe (>=0.2.7,<0.3.0)"]
testing = ["beautifulsoup4", "coverage[toml]", "pytest (>=7,<8)", "pytest-cov", "pytest-param-files (>=0.3.4,<0.4.0)", "pytest-regressions", "sphinx-pytest"]
@@ -524,7 +524,7 @@ testing-docutils = ["pygments", "pytest (>=7,<8)", "pytest-param-files (>=0.3.4,
[[package]]
name = "nodeenv"
-version = "1.7.0"
+version = "1.8.0"
description = "Node.js virtual environment builder"
category = "dev"
optional = false
@@ -550,7 +550,7 @@ typing-extensions = {version = ">=3.7.4", markers = "python_version < \"3.8\""}
virtualenv = ">=14"
[package.extras]
-tox-to-nox = ["jinja2", "tox (<4)"]
+tox_to_nox = ["jinja2", "tox (<4)"]
[[package]]
name = "nox-poetry"
@@ -590,7 +590,7 @@ optional = true
python-versions = ">=2.6"
[[package]]
-name = "pillow"
+name = "Pillow"
version = "9.5.0"
description = "Python Imaging Library (Fork)"
category = "main"
@@ -603,7 +603,7 @@ tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "pa
[[package]]
name = "platformdirs"
-version = "3.5.0"
+version = "3.5.1"
description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
category = "main"
optional = false
@@ -613,7 +613,7 @@ python-versions = ">=3.7"
typing-extensions = {version = ">=4.5", markers = "python_version < \"3.8\""}
[package.extras]
-docs = ["furo (>=2023.3.27)", "proselint (>=0.13)", "sphinx (>=6.1.3)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)"]
+docs = ["furo (>=2023.3.27)", "proselint (>=0.13)", "sphinx (>=6.2.1)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)"]
test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.3.1)", "pytest-cov (>=4)", "pytest-mock (>=3.10)"]
[[package]]
@@ -667,7 +667,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
test = ["enum34", "ipaddress", "mock", "pywin32", "wmi"]
[[package]]
-name = "pygments"
+name = "Pygments"
version = "2.15.1"
description = "Pygments is a syntax highlighting package written in Python."
category = "main"
@@ -770,7 +770,7 @@ pytest = ">=5.3"
[[package]]
name = "pytest-xdist"
-version = "3.2.1"
+version = "3.3.0"
description = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs"
category = "dev"
optional = false
@@ -805,7 +805,7 @@ optional = false
python-versions = "*"
[[package]]
-name = "pyyaml"
+name = "PyYAML"
version = "6.0"
description = "YAML parser and emitter for Python"
category = "main"
@@ -845,7 +845,7 @@ urllib3 = ">=1.21.1,<3"
[package.extras]
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
-use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
+use_chardet_on_py3 = ["chardet (>=3.0.2,<6)"]
[[package]]
name = "requests-mock"
@@ -963,7 +963,7 @@ optional = true
python-versions = ">=3.7"
[[package]]
-name = "sphinx"
+name = "Sphinx"
version = "5.3.0"
description = "Python documentation generator"
category = "main"
@@ -1066,11 +1066,11 @@ python-versions = ">=3.7"
sphinx = ">=1.8"
[package.extras]
-code-style = ["pre-commit (==2.12.1)"]
+code_style = ["pre-commit (==2.12.1)"]
rtd = ["ipython", "myst-nb", "sphinx", "sphinx-book-theme", "sphinx-examples"]
[[package]]
-name = "sphinx-design"
+name = "sphinx_design"
version = "0.4.1"
description = "A sphinx extension for designing beautiful, view size responsive web components."
category = "main"
@@ -1081,13 +1081,13 @@ python-versions = ">=3.7"
sphinx = ">=4,<7"
[package.extras]
-code-style = ["pre-commit (>=2.12,<3.0)"]
+code_style = ["pre-commit (>=2.12,<3.0)"]
rtd = ["myst-parser (>=0.18.0,<2)"]
testing = ["myst-parser (>=0.18.0,<2)", "pytest (>=7.1,<8.0)", "pytest-cov", "pytest-regressions"]
-theme-furo = ["furo (>=2022.06.04,<2022.07)"]
-theme-pydata = ["pydata-sphinx-theme (>=0.9.0,<0.10.0)"]
-theme-rtd = ["sphinx-rtd-theme (>=1.0,<2.0)"]
-theme-sbt = ["sphinx-book-theme (>=0.3.0,<0.4.0)"]
+theme_furo = ["furo (>=2022.06.04,<2022.07)"]
+theme_pydata = ["pydata-sphinx-theme (>=0.9.0,<0.10.0)"]
+theme_rtd = ["sphinx-rtd-theme (>=1.0,<2.0)"]
+theme_sbt = ["sphinx-book-theme (>=0.3.0,<0.4.0)"]
[[package]]
name = "sphinx-notfound-page"
@@ -1367,7 +1367,7 @@ attrs = [
{file = "attrs-23.1.0-py3-none-any.whl", hash = "sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04"},
{file = "attrs-23.1.0.tar.gz", hash = "sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015"},
]
-babel = [
+Babel = [
{file = "Babel-2.12.1-py3-none-any.whl", hash = "sha256:b4246fb7677d3b98f501a39d43396d3cafdc8eadb045f4a31be01863f655c610"},
{file = "Babel-2.12.1.tar.gz", hash = "sha256:cc2d99999cd01d44420ae725a21c9e3711b3aadc7976d6147f622d8581963455"},
]
@@ -1376,12 +1376,12 @@ beautifulsoup4 = [
{file = "beautifulsoup4-4.12.2.tar.gz", hash = "sha256:492bbc69dca35d12daac71c4db1bfff0c876c00ef4a2ffacce226d4638eb72da"},
]
boto3 = [
- {file = "boto3-1.26.129-py3-none-any.whl", hash = "sha256:1dab3fcbeada61a3b5a42ea25a89143511a5b22626775c685e31e313f327cf3c"},
- {file = "boto3-1.26.129.tar.gz", hash = "sha256:0686a62f424c4f3375a706555b765d1e24d03d70e7d317ffcb2d411b39aa8139"},
+ {file = "boto3-1.26.133-py3-none-any.whl", hash = "sha256:62285ecee7629a4388d55ae369536f759622d68d5b9a0ced7c58a0c1a409c0f7"},
+ {file = "boto3-1.26.133.tar.gz", hash = "sha256:8ff0af0b25266a01616396abc19eb34dc3d44bd867fa4158985924128b9034fb"},
]
botocore = [
- {file = "botocore-1.29.129-py3-none-any.whl", hash = "sha256:f44460236324727615c518c229690c3cc3ea3162a55a2ac242ba771e8fa41553"},
- {file = "botocore-1.29.129.tar.gz", hash = "sha256:80370e835ccf12e0429d4c6cc0e9d03cf47b72c41ec5916b01fb9544765f314d"},
+ {file = "botocore-1.29.133-py3-none-any.whl", hash = "sha256:b266185d7414a559952569005009a400de50af91fd3da44f05cf05b00946c4a7"},
+ {file = "botocore-1.29.133.tar.gz", hash = "sha256:7b38e540f73c921d8cb0ac72794072000af9e10758c04ba7f53d5629cc52fa87"},
]
bson = [
{file = "bson-0.5.10.tar.gz", hash = "sha256:d6511b2ab051139a9123c184de1a04227262173ad593429d21e443d6462d6590"},
@@ -1596,7 +1596,7 @@ itsdangerous = [
{file = "itsdangerous-2.1.2-py3-none-any.whl", hash = "sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44"},
{file = "itsdangerous-2.1.2.tar.gz", hash = "sha256:5dbbc68b317e5e42f327f9021763545dc3fc3bfe22e6deb96aaf1fc38874156a"},
]
-jinja2 = [
+Jinja2 = [
{file = "Jinja2-3.1.2-py3-none-any.whl", hash = "sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61"},
{file = "Jinja2-3.1.2.tar.gz", hash = "sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852"},
]
@@ -1685,7 +1685,7 @@ markdown-it-py = [
{file = "markdown-it-py-2.2.0.tar.gz", hash = "sha256:7c9a5e412688bc771c67432cbfebcdd686c93ce6484913dccf06cb5a0bea35a1"},
{file = "markdown_it_py-2.2.0-py3-none-any.whl", hash = "sha256:5a35f8d1870171d9acc47b99612dc146129b631baf04970128b568f190d0cc30"},
]
-markupsafe = [
+MarkupSafe = [
{file = "MarkupSafe-2.1.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:665a36ae6f8f20a4676b53224e33d456a6f5a72657d9c83c2aa00765072f31f7"},
{file = "MarkupSafe-2.1.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:340bea174e9761308703ae988e982005aedf427de816d1afe98147668cc03036"},
{file = "MarkupSafe-2.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:22152d00bf4a9c7c83960521fc558f55a1adbc0631fbb00a9471e097b19d72e1"},
@@ -1787,8 +1787,8 @@ myst-parser = [
{file = "myst_parser-1.0.0-py3-none-any.whl", hash = "sha256:69fb40a586c6fa68995e6521ac0a525793935db7e724ca9bac1d33be51be9a4c"},
]
nodeenv = [
- {file = "nodeenv-1.7.0-py2.py3-none-any.whl", hash = "sha256:27083a7b96a25f2f5e1d8cb4b6317ee8aeda3bdd121394e5ac54e498028a042e"},
- {file = "nodeenv-1.7.0.tar.gz", hash = "sha256:e0e7f7dfb85fc5394c6fe1e8fa98131a2473e04311a45afb6508f7cf1836fa2b"},
+ {file = "nodeenv-1.8.0-py2.py3-none-any.whl", hash = "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec"},
+ {file = "nodeenv-1.8.0.tar.gz", hash = "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2"},
]
nox = [
{file = "nox-2023.4.22-py3-none-any.whl", hash = "sha256:0b1adc619c58ab4fa57d6ab2e7823fe47a32e70202f287d78474adcc7bda1891"},
@@ -1836,7 +1836,7 @@ pbr = [
{file = "pbr-5.11.1-py2.py3-none-any.whl", hash = "sha256:567f09558bae2b3ab53cb3c1e2e33e726ff3338e7bae3db5dc954b3a44eef12b"},
{file = "pbr-5.11.1.tar.gz", hash = "sha256:aefc51675b0b533d56bb5fd1c8c6c0522fe31896679882e1c4c63d5e4a0fccb3"},
]
-pillow = [
+Pillow = [
{file = "Pillow-9.5.0-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:ace6ca218308447b9077c14ea4ef381ba0b67ee78d64046b3f19cf4e1139ad16"},
{file = "Pillow-9.5.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d3d403753c9d5adc04d4694d35cf0391f0f3d57c8e0030aac09d7678fa8030aa"},
{file = "Pillow-9.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5ba1b81ee69573fe7124881762bb4cd2e4b6ed9dd28c9c60a632902fe8db8b38"},
@@ -1905,8 +1905,8 @@ pillow = [
{file = "Pillow-9.5.0.tar.gz", hash = "sha256:bf548479d336726d7a0eceb6e767e179fbde37833ae42794602631a070d630f1"},
]
platformdirs = [
- {file = "platformdirs-3.5.0-py3-none-any.whl", hash = "sha256:47692bc24c1958e8b0f13dd727307cff1db103fca36399f457da8e05f222fdc4"},
- {file = "platformdirs-3.5.0.tar.gz", hash = "sha256:7954a68d0ba23558d753f73437c55f89027cf8f5108c19844d4b82e5af396335"},
+ {file = "platformdirs-3.5.1-py3-none-any.whl", hash = "sha256:e2378146f1964972c03c085bb5662ae80b2b8c06226c54b2ff4aa9483e8a13a5"},
+ {file = "platformdirs-3.5.1.tar.gz", hash = "sha256:412dae91f52a6f84830f39a8078cecd0e866cb72294a5c66808e74d5e88d251f"},
]
pluggy = [
{file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"},
@@ -1936,7 +1936,7 @@ psutil = [
{file = "psutil-5.9.5-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:c607bb3b57dc779d55e1554846352b4e358c10fff3abf3514a7a6601beebdb30"},
{file = "psutil-5.9.5.tar.gz", hash = "sha256:5410638e4df39c54d957fc51ce03048acd8e6d60abc0f5107af51e5fb566eb3c"},
]
-pygments = [
+Pygments = [
{file = "Pygments-2.15.1-py3-none-any.whl", hash = "sha256:db2db3deb4b4179f399a09054b023b6a586b76499d36965813c71aa8ed7b5fd1"},
{file = "Pygments-2.15.1.tar.gz", hash = "sha256:8ace4d3c1dd481894b2005f560ead0f9f19ee64fe983366be1a21e171d12775c"},
]
@@ -2036,8 +2036,8 @@ pytest-rerunfailures = [
{file = "pytest_rerunfailures-10.3-py3-none-any.whl", hash = "sha256:6be6f96510bf94b54198bf15bc5568fe2cdff88e83875912e22d29810acf65ff"},
]
pytest-xdist = [
- {file = "pytest-xdist-3.2.1.tar.gz", hash = "sha256:1849bd98d8b242b948e472db7478e090bf3361912a8fed87992ed94085f54727"},
- {file = "pytest_xdist-3.2.1-py3-none-any.whl", hash = "sha256:37290d161638a20b672401deef1cba812d110ac27e35d213f091d15b8beb40c9"},
+ {file = "pytest-xdist-3.3.0.tar.gz", hash = "sha256:d42c9efb388da35480878ef4b2993704c6cea800c8bafbe85a8cdc461baf0748"},
+ {file = "pytest_xdist-3.3.0-py3-none-any.whl", hash = "sha256:76f7683d4f993eaff91c9cb0882de0465c4af9c6dd3debc903833484041edc1a"},
]
python-dateutil = [
{file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"},
@@ -2047,7 +2047,7 @@ pytz = [
{file = "pytz-2023.3-py2.py3-none-any.whl", hash = "sha256:a151b3abb88eda1d4e34a9814df37de2a80e301e68ba0fd856fb9b46bfbbbffb"},
{file = "pytz-2023.3.tar.gz", hash = "sha256:1d8ce29db189191fb55338ee6d0387d82ab59f3d00eac103412d64e0ebd0c588"},
]
-pyyaml = [
+PyYAML = [
{file = "PyYAML-6.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53"},
{file = "PyYAML-6.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c"},
{file = "PyYAML-6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc"},
@@ -2133,7 +2133,7 @@ soupsieve = [
{file = "soupsieve-2.4.1-py3-none-any.whl", hash = "sha256:1c1bfee6819544a3447586c889157365a27e10d88cde3ad3da0cf0ddf646feb8"},
{file = "soupsieve-2.4.1.tar.gz", hash = "sha256:89d12b2d5dfcd2c9e8c22326da9d9aa9cb3dfab0a83a024f05704076ee8d35ea"},
]
-sphinx = [
+Sphinx = [
{file = "Sphinx-5.3.0.tar.gz", hash = "sha256:51026de0a9ff9fc13c05d74913ad66047e104f56a129ff73e174eb5c3ee794b5"},
{file = "sphinx-5.3.0-py3-none-any.whl", hash = "sha256:060ca5c9f7ba57a08a1219e547b269fadf125ae25b06b9fa7f66768efb652d6d"},
]
@@ -2157,7 +2157,7 @@ sphinx-copybutton = [
{file = "sphinx-copybutton-0.5.2.tar.gz", hash = "sha256:4cf17c82fb9646d1bc9ca92ac280813a3b605d8c421225fd9913154103ee1fbd"},
{file = "sphinx_copybutton-0.5.2-py3-none-any.whl", hash = "sha256:fb543fd386d917746c9a2c50360c7905b605726b9355cd26e9974857afeae06e"},
]
-sphinx-design = [
+sphinx_design = [
{file = "sphinx_design-0.4.1-py3-none-any.whl", hash = "sha256:23bf5705eb31296d4451f68b0222a698a8a84396ffe8378dfd9319ba7ab8efd9"},
{file = "sphinx_design-0.4.1.tar.gz", hash = "sha256:5b6418ba4a2dc3d83592ea0ff61a52a891fe72195a4c3a18b2fa1c7668ce4708"},
]
diff --git a/requests_cache/models/raw_response.py b/requests_cache/models/raw_response.py
index ea51eb5..bc7704a 100644
--- a/requests_cache/models/raw_response.py
+++ b/requests_cache/models/raw_response.py
@@ -34,7 +34,6 @@ class CachedHTTPResponse(RichMixin, HTTPResponse):
reason: str = field(default=None)
request_url: str = field(default=None)
status: int = field(default=0)
- strict: int = field(default=0)
version: int = field(default=0)
def __init__(self, body: Optional[bytes] = None, **kwargs):
@@ -52,17 +51,27 @@ class CachedHTTPResponse(RichMixin, HTTPResponse):
kwargs = {k: getattr(raw, k, None) for k in fields_dict(cls).keys()}
kwargs['request_url'] = raw._request_url
- # Copy response data and restore response object to its original state
+ # Read and copy raw response data, and then restore response object to its previous state
+ # This is necessary so streaming responses behave consistently with or without the cache
if getattr(raw, '_fp', None) and not is_fp_closed(raw._fp):
- body = raw.read(decode_content=False)
- kwargs['body'] = body
- raw._fp = BytesIO(body)
- _ = response.content # This property reads, decodes, and stores response content
-
- # After reading, reset file pointer on original raw response
- raw._fp = BytesIO(body)
- raw._fp_bytes_read = 0
- raw.length_remaining = len(body)
+ # Body has already been read & decoded by requests
+ if getattr(raw, '_has_decoded_content', False):
+ body = response.content
+ kwargs['body'] = body
+ raw._fp = BytesIO(body)
+ raw._fp_bytes_read = 0
+ raw.length_remaining = len(body)
+ # Body has not yet been read
+ else:
+ body = raw.read(decode_content=False)
+ kwargs['body'] = body
+ raw._fp = BytesIO(body)
+ _ = response.content # This property reads, decodes, and stores response content
+
+ # After reading, reset file pointer on original raw response
+ raw._fp = BytesIO(body)
+ raw._fp_bytes_read = 0
+ raw.length_remaining = len(body)
return cls(**kwargs) # type: ignore # False positive in mypy 0.920+?
diff --git a/tests/integration/base_cache_test.py b/tests/integration/base_cache_test.py
index 3e4d230..44d45eb 100644
--- a/tests/integration/base_cache_test.py
+++ b/tests/integration/base_cache_test.py
@@ -261,21 +261,16 @@ class BaseCacheTest:
assert response.from_cache is True
assert response.is_expired is False
- @pytest.mark.parametrize('stream', [True, False])
- def test_decode_gzip_response(self, stream):
- """Test that gzip-compressed raw responses (including streamed responses) can be manually
- decompressed with `decode_content=True`
- """
+ def test_decode_gzip_response(self):
+ """Test that gzip-compressed responses read decompressed content with decode_content=True"""
session = self.init_session()
- response = session.get(httpbin('gzip'), stream=stream)
+ response = session.get(httpbin('gzip'))
assert b'gzipped' in response.content
- if stream is True:
- assert b'gzipped' in response.raw.read(None, decode_content=True)
response.raw._fp = BytesIO(response.content)
cached_response = CachedResponse.from_response(response)
assert b'gzipped' in cached_response.content
- assert b'gzipped' in cached_response.raw.read(None, decode_content=True)
+ assert b'gzipped' in cached_response.raw.read(amt=None, decode_content=True)
@pytest.mark.parametrize('decode_content', [True, False])
@pytest.mark.parametrize('url', [MOCKED_URL_JSON, MOCKED_URL_JSON_LIST])
diff --git a/tests/unit/models/test_raw_response.py b/tests/unit/models/test_raw_response.py
index 9ec1591..ea80e57 100644
--- a/tests/unit/models/test_raw_response.py
+++ b/tests/unit/models/test_raw_response.py
@@ -16,7 +16,6 @@ def test_from_response(mock_session):
if hasattr(response.raw, '_request_url'):
assert response.raw._request_url is raw.request_url is None
assert response.raw.status == raw.status == 200
- assert response.raw.strict == raw.strict == 0
assert response.raw.version == raw.version == 0