Skip to content

Commit b9bd9b3

Browse files
author
Ahmed TAHRI
committed
🔖 Release 3.1.3
**Fixed** - **oheaders** from a Response contains `Set-Cookie` entries when it should not. - Static type checker not accepting **list\[str\]** in values for argument **param**. - Static type checker not accepting **Iterable\[bytes\]** for **data**. - Function proxy_bypass_registry for Windows may be fooled by insufficient control on our end. Patch taken from idle upstream PR psf#6302 - SSLError message related to the certificate revocation could print `None` instead of `unspecified` for the reason. **Changed** - Allow setting `None` in max_size for **SharableLimitedDict** to remove limits. - Using `RLock` instead of `Lock` in **SharableLimitedDict**, and **InMemoryRevocationStatus** classes. **Misc** - Missing assert statements for test test_header_validation. - Unrelated warnings are now silent in our test suite. - Unexpected warning now trigger an error in our test suite. - Removed `tests.compat`. - Removed `test-readme`, `flake8`, and `publish` from Makefile. **Added** - Extra-dist install `http3` to force install HTTP/3 support in your environment if not present. - Extra-dist install `ocsp` to force install certificate revocation support in your environment if not present.
1 parent 5cb7c7b commit b9bd9b3

17 files changed

Lines changed: 107 additions & 139 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev", "pypy-3.8", "pypy-3.9"]
20-
os: [ubuntu-22.04, macOS-latest, windows-latest]
19+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.8", "pypy-3.9", "pypy-3.10"]
20+
os: [ubuntu-latest, macOS-latest, windows-latest]
2121
include:
2222
# pypy-3.7 on Windows and Mac OS currently fails trying to compile
2323
# cryptography. Moving pypy-3.7 to only test linux.

HISTORY.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
Release History
22
===============
33

4+
3.1.3 (2023-10-19)
5+
------------------
6+
7+
**Fixed**
8+
- **oheaders** from a Response contains `Set-Cookie` entries when it should not.
9+
- Static type checker not accepting **list\[str\]** in values for argument **param**.
10+
- Static type checker not accepting **Iterable\[bytes\]** for **data**.
11+
- Function proxy_bypass_registry for Windows may be fooled by insufficient control on our end.
12+
Patch taken from idle upstream PR https://github.com/psf/requests/pull/6302
13+
- SSLError message related to the certificate revocation could print `None` instead of `unspecified` for the reason.
14+
15+
**Changed**
16+
- Allow setting `None` in max_size for **SharableLimitedDict** to remove limits.
17+
- Using `RLock` instead of `Lock` in **SharableLimitedDict**, and **InMemoryRevocationStatus** classes.
18+
19+
**Misc**
20+
- Missing assert statements for test test_header_validation.
21+
- Unrelated warnings are now silent in our test suite.
22+
- Unexpected warning now trigger an error in our test suite.
23+
- Removed `tests.compat`.
24+
- Removed `test-readme`, `flake8`, and `publish` from Makefile.
25+
26+
**Added**
27+
- Extra-dist install `http3` to force install HTTP/3 support in your environment if not present.
28+
- Extra-dist install `ocsp` to force install certificate revocation support in your environment if not present.
29+
430
3.1.2 (2023-10-16)
531
------------------
632

Makefile

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,10 @@ test:
55
# This runs all of the tests on all supported Python versions.
66
tox -p
77
ci:
8-
python -m pytest tests --junitxml=report.xml
9-
10-
test-readme:
11-
python setup.py check --restructuredtext --strict && ([ $$? -eq 0 ] && echo "README.rst and HISTORY.rst ok") || echo "Invalid markup in README.rst or HISTORY.rst!"
12-
13-
flake8:
14-
python -m flake8 src/requests
8+
python -m pytest tests --verbose --junitxml=report.xml
159

1610
coverage:
17-
python -m pytest --cov-config .coveragerc --verbose --cov-report term --cov-report xml --cov=src/requests tests
18-
19-
publish:
20-
python -m pip install 'twine>=1.5.0'
21-
python setup.py sdist bdist_wheel
22-
twine upload dist/*
23-
rm -fr build dist .egg requests.egg-info
11+
python -m pytest --cov-config .coveragerc --verbose --cov-report term --cov-report xml --cov=niquests tests
2412

2513
docs:
2614
cd docs && make html

docs/user/advanced.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,3 +1209,22 @@ This would mean that attempting to request ``https://cloudflare.com/a/b`` will b
12091209
over QUIC.
12101210

12111211
.. warning:: You cannot specify another hostname for security reasons.
1212+
1213+
Increase the default Alt-Svc cache size
1214+
---------------------------------------
1215+
1216+
When a server yield its support for HTTP/3 over QUIC, the information
1217+
is stored within a local thread safe in-memory storage.
1218+
1219+
That storage is limited to 12,288 entries by default, and you can override this
1220+
by passing a custom ``QuicSharedCache`` instance like so::
1221+
1222+
import niquests
1223+
1224+
cache = niquests.structures.QuicSharedCache(max_size=128_000)
1225+
session = niquests.Session(quic_cache_layer=cache)
1226+
1227+
1228+
.. note:: Passing ``None`` to max size actually permit the cache to grow indefinitely. This is unwise and can lead to significant RAM usage.
1229+
1230+
When the cache is full, the oldest entry is removed.

pyproject.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ dependencies = [
4848

4949
[project.optional-dependencies]
5050
socks = [
51-
"PySocks>=1.5.6, !=1.5.7",
51+
"PySocks>=1.5.6, !=1.5.7",
52+
]
53+
http3 = [
54+
"qh3<1.0.0,>=0.11.3"
55+
]
56+
ocsp = [
57+
"cryptography<42.0.0,>=41.0.0"
5258
]
5359

5460
[project.urls]
@@ -91,3 +97,11 @@ addopts = "--doctest-modules"
9197
doctest_optionflags = "NORMALIZE_WHITESPACE ELLIPSIS"
9298
minversion = "6.2"
9399
testpaths = ["tests"]
100+
filterwarnings = [
101+
"error",
102+
'''ignore:'parse_authorization_header' is deprecated and will be removed:DeprecationWarning''',
103+
'''ignore:The 'set_digest' method is deprecated and will be removed:UserWarning''',
104+
'''ignore:Passing bytes as a header value is deprecated and will:DeprecationWarning''',
105+
'''ignore:'JSONIFY_PRETTYPRINT_REGULAR' config key is deprecated and will be removed:DeprecationWarning''',
106+
'''ignore:unclosed .*:ResourceWarning''',
107+
]

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-e .[socks]
2-
pytest>=2.8.0,<=6.2.5
2+
pytest>=2.8.0,<=7.4.2
33
pytest-cov
44
pytest-httpbin==2.0.0
55
httpbin==0.10.1

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
ignore = E203, E501, W503
33
per-file-ignores =
44
src/niquests/__init__.py:E402, F401
5-
tests/compat.py:F401

src/niquests/__version__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
__url__: str = "https://niquests.readthedocs.io"
1010

1111
__version__: str
12-
__version__ = "3.1.2"
12+
__version__ = "3.1.3"
1313

14-
__build__: int = 0x030102
14+
__build__: int = 0x030103
1515
__author__: str = "Kenneth Reitz"
1616
__author_email__: str = "me@kennethreitz.org"
1717
__license__: str = "Apache-2.0"

src/niquests/_typing.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
)
1717
#: List of formats accepted for URL queries parameters. (e.g. /?param1=a&param2=b)
1818
QueryParameterType: typing.TypeAlias = typing.Union[
19-
typing.List[typing.Tuple[str, str]],
20-
typing.Mapping[str, str],
19+
typing.List[typing.Tuple[str, typing.Union[str, typing.List[str]]]],
20+
typing.Mapping[str, typing.Union[str, typing.List[str]]],
2121
bytes,
2222
str,
2323
]
@@ -32,6 +32,7 @@
3232
bytearray,
3333
typing.IO,
3434
BodyFormType,
35+
typing.Iterable[bytes],
3536
]
3637
#: HTTP Headers can be represented through three ways. 1) typical dict, 2) internal insensitive dict, and 3) list of tuple.
3738
HeadersType: typing.TypeAlias = typing.Union[
@@ -123,9 +124,7 @@
123124
_HV = typing.TypeVar("_HV")
124125

125126
HookCallableType: typing.TypeAlias = typing.Callable[
126-
[
127-
_HV,
128-
],
127+
[_HV],
129128
typing.Optional[_HV],
130129
]
131130

src/niquests/extensions/_ocsp.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def _str_fingerprint_of(certificate: Certificate) -> str:
5353
def _infer_issuer_from(certificate: Certificate) -> Certificate | None:
5454
issuer: Certificate | None = None
5555

56-
for der_cert in wassima.root_der_certificates() + _SharedStaplingCache.issuers:
56+
for der_cert in (
57+
wassima.root_der_certificates() + _SharedRevocationStatusCache.issuers
58+
):
5759
if isinstance(der_cert, Certificate):
5860
possible_issuer = der_cert
5961
else:
@@ -197,7 +199,7 @@ def __init__(self, max_size: int = 2048):
197199
self._store: dict[str, ocsp.OCSPResponse] = {}
198200
self._issuers: list[Certificate] = []
199201
self._timings: list[datetime.datetime] = []
200-
self._access_lock: threading.Lock = threading.Lock()
202+
self._access_lock = threading.RLock()
201203
self.hold: bool = False
202204

203205
@property
@@ -295,7 +297,7 @@ def save(
295297
self._timings.pop(0)
296298

297299

298-
_SharedStaplingCache = InMemoryRevocationStatus()
300+
_SharedRevocationStatusCache = InMemoryRevocationStatus()
299301

300302

301303
def verify(
@@ -327,17 +329,17 @@ def verify(
327329

328330
# this feature, by default, is reserved for a reasonable usage.
329331
if not strict:
330-
mean_rate_sec = _SharedStaplingCache.rate()
331-
cache_count = len(_SharedStaplingCache)
332+
mean_rate_sec = _SharedRevocationStatusCache.rate()
333+
cache_count = len(_SharedRevocationStatusCache)
332334

333335
if cache_count >= 10 and mean_rate_sec <= 1.0:
334-
_SharedStaplingCache.hold = True
336+
_SharedRevocationStatusCache.hold = True
335337

336-
if _SharedStaplingCache.hold:
338+
if _SharedRevocationStatusCache.hold:
337339
return
338340

339341
peer_certificate = load_der_x509_certificate(conn_info.certificate_der)
340-
cached_response = _SharedStaplingCache.check(peer_certificate)
342+
cached_response = _SharedRevocationStatusCache.check(peer_certificate)
341343

342344
if cached_response is not None:
343345
issuer_certificate = _infer_issuer_from(peer_certificate)
@@ -352,7 +354,7 @@ def verify(
352354
r.ocsp_verified = False
353355
raise SSLError(
354356
f"""Unable to establish a secure connection to {r.url} because the certificate has been revoked
355-
by issuer ({cached_response.revocation_reason}).
357+
by issuer ({cached_response.revocation_reason or "unspecified"}).
356358
You should avoid trying to request anything from it as the remote has been compromised.
357359
See https://en.wikipedia.org/wiki/OCSP_stapling for more information."""
358360
)
@@ -479,14 +481,16 @@ def verify(
479481

480482
ocsp_resp = ocsp.load_der_ocsp_response(ocsp_http_response.content)
481483

482-
_SharedStaplingCache.save(peer_certificate, issuer_certificate, ocsp_resp)
484+
_SharedRevocationStatusCache.save(
485+
peer_certificate, issuer_certificate, ocsp_resp
486+
)
483487

484488
if ocsp_resp.response_status == ocsp.OCSPResponseStatus.SUCCESSFUL:
485489
if ocsp_resp.certificate_status == ocsp.OCSPCertStatus.REVOKED:
486490
r.ocsp_verified = False
487491
raise SSLError(
488492
f"""Unable to establish a secure connection to {r.url} because the certificate has been revoked
489-
by issuer ({ocsp_resp.revocation_reason}).
493+
by issuer ({ocsp_resp.revocation_reason or "unspecified"}).
490494
You should avoid trying to request anything from it as the remote has been compromised.
491495
See https://en.wikipedia.org/wiki/OCSP_stapling for more information."""
492496
)

0 commit comments

Comments
 (0)