Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES/13029.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed a deprecation warning during request initialization by allowing
``BaseRequest`` to assign ``_transport_sockname``.
-- by :user:`nightcityblade`.
1 change: 1 addition & 0 deletions aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class BaseRequest(MutableMapping[str | RequestKey[Any], Any], HeadersMixin):
"_loop",
"_transport_sslcontext",
"_transport_peername",
"_transport_sockname",
]
)
_post: MultiDictProxy[_Post] | None = None
Expand Down
23 changes: 23 additions & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,29 @@ def test_host_with_no_transport_sockname() -> None:
assert req.host == ""


def test_request_init_allows_transport_sockname_assignment() -> None:
message = make_mocked_request("GET", "/")._message
payload = mock.Mock()
payload_writer = mock.Mock()
task = mock.Mock()
loop = mock.Mock()
protocol = mock.Mock()
protocol.ssl_context = None
protocol.peername = None
protocol.sockname = ("127.0.0.1", 8080)

req = BaseRequest(
message,
payload,
protocol,
payload_writer,
task,
loop,
)

assert req._transport_sockname == ("127.0.0.1", 8080)


def test_doubleslashes() -> None:
# NB: //foo/bar is an absolute URL with foo netloc and /bar path
req = make_mocked_request("GET", "/bar//foo/")
Expand Down
Loading