Skip to content

Commit

Permalink
Merge branch 'master' into hyperscan
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Nov 19, 2024
2 parents c82a824 + 3e81852 commit e1cbdf0
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 13 deletions.
70 changes: 70 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,76 @@

.. towncrier release notes start
3.11.4 (2024-11-18)
===================

Bug fixes
---------

- Fixed ``StaticResource`` not allowing the ``OPTIONS`` method after calling ``set_options_route`` -- by :user:`bdraco`.


*Related issues and pull requests on GitHub:*
:issue:`9972`, :issue:`9975`, :issue:`9976`.




Miscellaneous internal changes
------------------------------

- Improved performance of creating web responses when there are no cookies -- by :user:`bdraco`.


*Related issues and pull requests on GitHub:*
:issue:`9895`.




----


3.11.3 (2024-11-18)
===================

Bug fixes
---------

- Removed non-existing ``__author__`` from ``dir(aiohttp)`` -- by :user:`Dreamsorcerer`.


*Related issues and pull requests on GitHub:*
:issue:`9918`.



- Restored the ``FlowControlDataQueue`` class -- by :user:`bdraco`.

This class is no longer used internally, and will be permanently removed in the next major version.


*Related issues and pull requests on GitHub:*
:issue:`9963`.




Miscellaneous internal changes
------------------------------

- Improved performance of resolving resources when multiple methods are registered for the same route -- by :user:`bdraco`.


*Related issues and pull requests on GitHub:*
:issue:`9899`.




----


3.11.2 (2024-11-14)
===================

Expand Down
1 change: 0 additions & 1 deletion CHANGES/9899.misc.rst

This file was deleted.

1 change: 0 additions & 1 deletion CHANGES/9918.bugfix.rst

This file was deleted.

13 changes: 7 additions & 6 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,10 +921,12 @@ def __init__(self) -> None:
super().__init__()
# Mypy doesn't like that _cookies isn't in __slots__.
# See the comment on this class's __slots__ for why this is OK.
self._cookies = SimpleCookie() # type: ignore[misc]
self._cookies: Optional[SimpleCookie] = None # type: ignore[misc]

@property
def cookies(self) -> SimpleCookie:
if self._cookies is None:
self._cookies = SimpleCookie() # type: ignore[misc]
return self._cookies

def set_cookie(
Expand All @@ -945,10 +947,8 @@ def set_cookie(
Sets new cookie or updates existent with new value.
Also updates only those params which are not None.
"""
old = self._cookies.get(name)
if old is not None and old.coded_value == "":
# deleted cookie
self._cookies.pop(name, None)
if self._cookies is None:
self._cookies = SimpleCookie() # type: ignore[misc]

self._cookies[name] = value
c = self._cookies[name]
Expand Down Expand Up @@ -999,7 +999,8 @@ def del_cookie(
Creates new empty expired cookie.
"""
# TODO: do we need domain/path here?
self._cookies.pop(name, None)
if self._cookies is not None:
self._cookies.pop(name, None)
self.set_cookie(
name,
"",
Expand Down
1 change: 1 addition & 0 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ def set_options_route(self, handler: Handler) -> None:
self._routes["OPTIONS"] = ResourceRoute(
"OPTIONS", handler, self, expect_handler=self._expect_handler
)
self._allowed_methods.add("OPTIONS")

async def resolve(self, request: Request) -> _Resolve:
path = request.rel_url.path_safe
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ typing-extensions==4.12.2
# via multidict
uvloop==0.21.0 ; platform_system != "Windows" and implementation_name == "cpython"
# via -r requirements/base.in
yarl==1.17.1
yarl==1.17.2
# via -r requirements/runtime-deps.in
2 changes: 1 addition & 1 deletion requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ wait-for-it==2.2.2
# via -r requirements/test.in
wheel==0.44.0
# via pip-tools
yarl==1.17.1
yarl==1.17.2
# via -r requirements/runtime-deps.in
zipp==3.20.2
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ wait-for-it==2.2.2
# via -r requirements/test.in
wheel==0.44.0
# via pip-tools
yarl==1.17.1
yarl==1.17.2
# via -r requirements/runtime-deps.in
zipp==3.20.2
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/runtime-deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ pycparser==2.22
# via cffi
typing-extensions==4.12.2
# via multidict
yarl==1.17.1
yarl==1.17.2
# via -r requirements/runtime-deps.in
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ uvloop==0.21.0 ; platform_system != "Windows" and implementation_name == "cpytho
# via -r requirements/base.in
wait-for-it==2.2.2
# via -r requirements/test.in
yarl==1.17.1
yarl==1.17.2
# via -r requirements/runtime-deps.in
7 changes: 7 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,11 @@ def test_cookies_mixin() -> None:

sut.set_cookie("name", "value")
assert str(sut.cookies) == "Set-Cookie: name=value; Path=/"
sut.set_cookie("name", "")
assert str(sut.cookies) == 'Set-Cookie: name=""; Path=/'
sut.set_cookie("name", "value")
assert str(sut.cookies) == "Set-Cookie: name=value; Path=/"

sut.set_cookie("name", "other_value")
assert str(sut.cookies) == "Set-Cookie: name=other_value; Path=/"

Expand All @@ -931,6 +936,8 @@ def test_cookies_mixin() -> None:
"expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/"
)
assert str(sut.cookies) == expected
sut.del_cookie("name")
assert str(sut.cookies) == expected

sut.set_cookie("name", "value", domain="local.host")
expected = "Set-Cookie: name=value; Domain=local.host; Path=/"
Expand Down
36 changes: 36 additions & 0 deletions tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,42 @@ async def test_static_not_match(router: web.UrlDispatcher) -> None:
assert (None, set()) == ret


async def test_add_static_access_resources(router: web.UrlDispatcher) -> None:
"""Test accessing resource._routes externally.
aiohttp-cors accesses the resource._routes, this test ensures that this
continues to work.
"""
# https://github.com/aio-libs/aiohttp-cors/blob/38c6c17bffc805e46baccd7be1b4fd8c69d95dc3/aiohttp_cors/urldispatcher_router_adapter.py#L187
resource = router.add_static(
"/st", pathlib.Path(aiohttp.__file__).parent, name="static"
)
resource._routes[hdrs.METH_OPTIONS] = resource._routes[hdrs.METH_GET]
resource._allowed_methods.add(hdrs.METH_OPTIONS)
mapping, allowed_methods = await resource.resolve(
make_mocked_request("OPTIONS", "/st/path")
)
assert mapping is not None
assert allowed_methods == {hdrs.METH_GET, hdrs.METH_OPTIONS, hdrs.METH_HEAD}


async def test_add_static_set_options_route(router: web.UrlDispatcher) -> None:
"""Ensure set_options_route works as expected."""
resource = router.add_static(
"/st", pathlib.Path(aiohttp.__file__).parent, name="static"
)

async def handler(request: web.Request) -> NoReturn:
assert False

resource.set_options_route(handler)
mapping, allowed_methods = await resource.resolve(
make_mocked_request("OPTIONS", "/st/path")
)
assert mapping is not None
assert allowed_methods == {hdrs.METH_GET, hdrs.METH_OPTIONS, hdrs.METH_HEAD}


def test_dynamic_with_trailing_slash(router: web.UrlDispatcher) -> None:
handler = make_handler()
router.add_route("GET", "/get/{name}/", handler, name="name")
Expand Down

0 comments on commit e1cbdf0

Please sign in to comment.