Skip to content

Commit

Permalink
Merge pull request #1371 from jcass77/enhance/format_proxy
Browse files Browse the repository at this point in the history
Handle missing or empty 'port' configuration parameter.
  • Loading branch information
jodal committed Dec 29, 2015
2 parents 4fba994 + 3488e64 commit 811131f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mopidy/httpclient.py
Expand Up @@ -21,8 +21,8 @@ def format_proxy(proxy_config, auth=True):
if not proxy_config.get('hostname'):
return None

port = proxy_config.get('port', 80)
if port < 0:
port = proxy_config.get('port')
if not port or port < 0:
port = 80

if proxy_config.get('username') and proxy_config.get('password') and auth:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_httpclient.py
Expand Up @@ -9,13 +9,16 @@

@pytest.mark.parametrize("config,expected", [
({}, None),
({'hostname': ''}, None),
({'hostname': 'proxy.lan'}, 'http://proxy.lan:80'),
({'scheme': None, 'hostname': 'proxy.lan'}, 'http://proxy.lan:80'),
({'scheme': 'https', 'hostname': 'proxy.lan'}, 'https://proxy.lan:80'),
({'username': 'user', 'hostname': 'proxy.lan'}, 'http://proxy.lan:80'),
({'password': 'pass', 'hostname': 'proxy.lan'}, 'http://proxy.lan:80'),
({'hostname': 'proxy.lan', 'port': 8080}, 'http://proxy.lan:8080'),
({'hostname': 'proxy.lan', 'port': -1}, 'http://proxy.lan:80'),
({'hostname': 'proxy.lan', 'port': None}, 'http://proxy.lan:80'),
({'hostname': 'proxy.lan', 'port': ''}, 'http://proxy.lan:80'),
({'username': 'user', 'password': 'pass', 'hostname': 'proxy.lan'},
'http://user:pass@proxy.lan:80'),
])
Expand Down

0 comments on commit 811131f

Please sign in to comment.