Skip to content

Commit

Permalink
Fix Site.name with empty host (#8929)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Aug 29, 2024
1 parent daf899f commit c0c3376
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/8929.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ``Site.name`` when host is an empty string -- by :user:`Dreamsorcerer`.
2 changes: 1 addition & 1 deletion aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(
@property
def name(self) -> str:
scheme = "https" if self._ssl_context else "http"
host = "0.0.0.0" if self._host is None else self._host
host = "0.0.0.0" if not self._host else self._host
return str(URL.build(scheme=scheme, host=host, port=self._port))

async def start(self) -> None:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ async def mock_create_server(*args, **kwargs):
assert port == 8080


async def test_tcpsite_empty_str_host(make_runner: Any) -> None:
runner = make_runner()
await runner.setup()
site = web.TCPSite(runner, host="")
assert site.name == "http://0.0.0.0:8080"


def test_run_after_asyncio_run() -> None:
async def nothing():
pass
Expand Down

0 comments on commit c0c3376

Please sign in to comment.