Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix web.run_app not to bind to default host:port if only socket is passed #1786

Merged
merged 3 commits into from
Apr 5, 2017
Merged
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.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Changes

- Dropped "%O" in access logger #1673

- Fix ``web.run_app`` not to bind to default host-port pair if only socket is
passed #1786


2.0.6 (2017-04-04)
------------------
Expand Down
16 changes: 8 additions & 8 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,15 @@ def run_app(app, *, host=None, port=None, path=None, sock=None,
else:
paths = path

if sock is None:
socks = ()
elif not isinstance(sock, Iterable):
socks = (sock,)
else:
socks = sock

if host is None:
if paths and not port:
if (paths or socks) and not port:
hosts = ()
else:
hosts = ("0.0.0.0",)
Expand All @@ -345,13 +352,6 @@ def run_app(app, *, host=None, port=None, path=None, sock=None,
if hosts and port is None:
port = 8443 if ssl_context else 8080

if sock is None:
socks = ()
elif not isinstance(sock, Iterable):
socks = (sock,)
else:
socks = sock

server_creations = []
uris = [str(base_url.with_host(host)) for host in hosts]
if hosts:
Expand Down
23 changes: 22 additions & 1 deletion tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_run_app_http(loop, mocker):
mock_server_default_8989 = [
mock.call(mock.ANY, '0.0.0.0', 8989, ssl=None, backlog=128)
]
mock_socket = mock.Mock(getsockname=lambda: ('mock-socket', 123))
mixed_bindings_tests = (
(
"Nothing Specified",
Expand Down Expand Up @@ -136,7 +137,27 @@ def test_run_app_http(loop, mocker):
[mock.call(mock.ANY, ('127.0.0.1', '192.168.1.1'), 8000, ssl=None,
backlog=128)],
mock_unix_server_multi
)
),
(
"Only socket",
{"sock": [mock_socket]},
[mock.call(mock.ANY, ssl=None, sock=mock_socket, backlog=128)],
[],
),
(
"Socket, port",
{"sock": [mock_socket], "port": 8765},
[mock.call(mock.ANY, '0.0.0.0', 8765, ssl=None, backlog=128),
mock.call(mock.ANY, sock=mock_socket, ssl=None, backlog=128)],
[],
),
(
"Socket, Host, No port",
{"sock": [mock_socket], "host": 'localhost'},
[mock.call(mock.ANY, 'localhost', 8080, ssl=None, backlog=128),
mock.call(mock.ANY, sock=mock_socket, ssl=None, backlog=128)],
[],
),
)
mixed_bindings_test_ids = [test[0] for test in mixed_bindings_tests]
mixed_bindings_test_params = [test[1:] for test in mixed_bindings_tests]
Expand Down