Skip to content

Commit

Permalink
🔖 Release 3.4.1 (#62)
Browse files Browse the repository at this point in the history
**Fixed**

- CaseInsensibleDict did not properly convert HTTPHeaderDict from
urllib3 thus only letting the last entry in.
- Redirect chain lead to a non waited coroutine in `AsyncSession`.
  • Loading branch information
Ousret authored Jan 7, 2024
1 parent 17383fa commit f173bdc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release History
===============

3.4.1 (2024-01-07)
------------------

**Fixed**
- CaseInsensibleDict did not properly convert HTTPHeaderDict from urllib3 thus only letting the last entry in.
- Redirect chain lead to a non waited coroutine in `AsyncSession`.

3.4.0 (2024-01-01)
------------------

Expand Down
4 changes: 2 additions & 2 deletions src/niquests/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
__url__: str = "https://niquests.readthedocs.io"

__version__: str
__version__ = "3.4.0"
__version__ = "3.4.1"

__build__: int = 0x030400
__build__: int = 0x030401
__author__: str = "Kenneth Reitz"
__author_email__: str = "me@kennethreitz.org"
__license__: str = "Apache-2.0"
Expand Down
32 changes: 22 additions & 10 deletions src/niquests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,16 +1518,28 @@ def resolve_redirects(
else:
if yield_requests_trail:
yield req
resp = self.send(
req,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
allow_redirects=False,
**adapter_kwargs,
)
if "AsyncSession" not in str(type(self)):
resp = self.send(
req,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
allow_redirects=False,
**adapter_kwargs,
)
else:
resp = super(self.__class__, self).send( # type: ignore[misc]
req,
stream=stream,
timeout=timeout,
verify=verify,
cert=cert,
proxies=proxies,
allow_redirects=False,
**adapter_kwargs,
)

extract_cookies_to_jar(self.cookies, prepared_request, resp.raw)

Expand Down
3 changes: 3 additions & 0 deletions src/niquests/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def __init__(self, data=None, **kwargs) -> None:
] = OrderedDict()
if data is None:
data = {}
fmt_data = str(type(data))
if "urllib3" in fmt_data and "HTTPHeaderDict" in fmt_data:
data = dict(data)
normalized_items = []
for k, v in data.items() if hasattr(data, "items") else data:
normalized_items.append(_ensure_str_or_bytes(k, v))
Expand Down
7 changes: 7 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ async def test_awaitable_get(self):
assert resp.lazy is False
assert resp.status_code == 200

async def test_awaitable_redirect_chain(self):
async with AsyncSession() as s:
resp = await s.get("https://pie.dev/redirect/2")

assert resp.lazy is False
assert resp.status_code == 200

async def test_concurrent_task_get(self):
async def emit():
responses = []
Expand Down
11 changes: 11 additions & 0 deletions tests/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from niquests.structures import CaseInsensitiveDict, LookupDict
from urllib3 import HTTPHeaderDict


class TestCaseInsensitiveDict:
Expand Down Expand Up @@ -52,6 +53,16 @@ def test_copy(self):
def test_instance_equality(self, other, result):
assert (self.case_insensitive_dict == other) is result

def test_lossless_convert_into_mono_entry(self):
o = HTTPHeaderDict()
o.add("Hello", "1")
o.add("Hello", "2")
o.add("Hello", "3")

u = CaseInsensitiveDict(o)

assert u["Hello"] == "1, 2, 3"


class TestLookupDict:
@pytest.fixture(autouse=True)
Expand Down

0 comments on commit f173bdc

Please sign in to comment.