Skip to content
Myr

Merge pull request #2928 from vorelq/2926-default-port-overrides-zero

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #2926 `Default port overrides requesting a system assigned port`

authored by David Lord · committed by GitHub · parents 05102f6, e1cc16f · Browse files · 3 files+14 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+14 added−8 removed

  • tests:+10 added−7 removed
  • other:+4 added−1 removed

3 files+14 added−8 removed

modified:flask/app.py+2 added-1 removed
970 unmodified lines
971 if server_name:972 sn_host, _, sn_port = server_name.partition(":")973974 host = host or sn_host or _host975 port = int(port or sn_port or _port)975 # pick the first value that's not None (0 is allowed)976 port = int(next((p for p in (port, sn_port) if p is not None), _port))977978 options.setdefault("use_reloader", self.debug)979 options.setdefault("use_debugger", self.debug)980 options.setdefault("threaded", True)
1434 unmodified lines
modified:tests/test_basic.py+10 added-7 removed
1914 unmodified lines
1915 assert rv["result"] == "running on %s:%s ..." % (hostname, port)191619171918@pytest.mark.parametrize(1919 "host,port,expect_host,expect_port",1919 "host,port,server_name,expect_host,expect_port",1920 (1921 (None, None, "pocoo.org", 8080),1922 ("localhost", None, "localhost", 8080),1923 (None, 80, "pocoo.org", 80),1924 ("localhost", 80, "localhost", 80),1921 (None, None, "pocoo.org:8080", "pocoo.org", 8080),1922 ("localhost", None, "pocoo.org:8080", "localhost", 8080),1923 (None, 80, "pocoo.org:8080", "pocoo.org", 80),1924 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1925 ("localhost", 0, "localhost:8080", "localhost", 0),1926 (None, None, "localhost:8080", "localhost", 8080),1927 (None, None, "localhost:0", "localhost", 0),1928 ),1929)1927def test_run_from_config(monkeypatch, host, port, expect_host, expect_port, app):1930def test_run_from_config(monkeypatch, host, port, server_name, expect_host, expect_port, app):1931 def run_simple_mock(hostname, port, *args, **kwargs):1932 assert hostname == expect_host1933 assert port == expect_port19341935 monkeypatch.setattr(werkzeug.serving, "run_simple", run_simple_mock)1933 app.config["SERVER_NAME"] = "pocoo.org:8080"1936 app.config["SERVER_NAME"] = server_name1937 app.run(host, port)193819391940def test_max_cookie_size(app, client, recwarn):
27 unmodified lines
modified:CHANGES.rst+2 added
40 unmodified lines
41- :meth:`jsonify` supports :class:`dataclasses.dataclass` objects.42 :pr:`3195`43- Allow customizing the :attr:`Flask.url_map_class` used for routing.44 :pr:`3069`45- The development server port can be set to 0, which tells the OS to46 pick an available port. :issue:`2926`4748.. _#2935: https://github.com/pallets/flask/issues/293549.. _#2957: https://github.com/pallets/flask/issues/295750.. _#2994: https://github.com/pallets/flask/pull/2994
948 unmodified lines