Improve parsing of 'unix://' addresses in parse_address (#1623)

This commit is contained in:
Hasan Ramezani 2017-10-16 10:14:00 +03:30 committed by Berker Peksag
parent e868c52997
commit 81efa40da7
2 changed files with 15 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import inspect
import errno
import warnings
import logging
import re
from gunicorn import _compat
from gunicorn.errors import AppImportError
@ -232,11 +233,8 @@ def is_ipv6(addr):
def parse_address(netloc, default_port=8000):
if netloc.startswith("unix://"):
return netloc.split("unix://")[1]
if netloc.startswith("unix:"):
return netloc.split("unix:")[1]
if re.match(r'unix:(//)?', netloc):
return re.split(r'unix:(//)?', netloc)[-1]
if netloc.startswith("tcp://"):
netloc = netloc.split("tcp://")[1]

12
tests/test_util.py Normal file
View File

@ -0,0 +1,12 @@
# -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
from gunicorn import util
def test_parse_address():
# Test unix socket addresses (PR #1623)
assert util.parse_address('unix://var/run/test.sock') == 'var/run/test.sock'
assert util.parse_address('unix:/var/run/test.sock') == '/var/run/test.sock'