-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Issue #1719: resolving hostnames for bind #1723
base: master
Are you sure you want to change the base?
Changes from 7 commits
f3ceae2
b1779b5
61ea13e
f0f2928
06bd5d4
3f633ec
0c45c4a
25935b7
4874c1b
2bdd721
c94048e
d3568c8
7904f3f
0ebf15c
6f91687
51466dc
c597560
4c20ec1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,7 +122,11 @@ def worker_class(self): | |
@property | ||
def address(self): | ||
s = self.settings['bind'].get() | ||
return [util.parse_address(_compat.bytes_to_str(bind)) for bind in s] | ||
|
||
addresses = [] | ||
for bind in s: | ||
addresses.extend(util.parse_address(_compat.bytes_to_str(bind))) | ||
return addresses | ||
|
||
@property | ||
def uid(self): | ||
|
@@ -534,9 +538,9 @@ class Bind(Setting): | |
validator = validate_list_string | ||
|
||
if 'PORT' in os.environ: | ||
default = ['0.0.0.0:{0}'.format(os.environ.get('PORT'))] | ||
default = ['[::]:{0}'.format(os.environ.get('PORT'))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least on my machine, this returns only IPv6 addresses from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you bind to :: you will listen to any address (IPv4 and IPv6) as long the IPV6_V6ONLY flag is not set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about the machine that doesn't support or has not been installed with ipv6 support? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The older version dosn't work on IPv6 installations at all. |
||
else: | ||
default = ['127.0.0.1:8000'] | ||
default = ['localhost:8000'] | ||
|
||
desc = """\ | ||
The socket to bind. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,12 @@ def __init__(self, address, conf, log, fd=None): | |
self.log = log | ||
self.conf = conf | ||
|
||
self.cfg_addr = address | ||
self.cfg_addr = address[4] | ||
if fd is None: | ||
sock = socket.socket(self.FAMILY, socket.SOCK_STREAM) | ||
sock = socket.socket(address[0], socket.SOCK_STREAM) | ||
bound = False | ||
else: | ||
sock = socket.fromfd(fd, self.FAMILY, socket.SOCK_STREAM) | ||
sock = socket.fromfd(fd, address[0], socket.SOCK_STREAM) | ||
os.close(fd) | ||
bound = True | ||
|
||
|
@@ -74,8 +74,6 @@ def close(self): | |
|
||
class TCPSocket(BaseSocket): | ||
|
||
FAMILY = socket.AF_INET | ||
|
||
def __str__(self): | ||
if self.conf.is_ssl: | ||
scheme = "https" | ||
|
@@ -92,27 +90,23 @@ def set_options(self, sock, bound=False): | |
|
||
class TCP6Socket(TCPSocket): | ||
|
||
FAMILY = socket.AF_INET6 | ||
|
||
def __str__(self): | ||
(host, port, _, _) = self.sock.getsockname() | ||
return "http://[%s]:%d" % (host, port) | ||
|
||
|
||
class UnixSocket(BaseSocket): | ||
|
||
FAMILY = socket.AF_UNIX | ||
|
||
def __init__(self, addr, conf, log, fd=None): | ||
if fd is None: | ||
try: | ||
st = os.stat(addr) | ||
st = os.stat(addr[4]) | ||
except OSError as e: | ||
if e.args[0] != errno.ENOENT: | ||
raise | ||
else: | ||
if stat.S_ISSOCK(st.st_mode): | ||
os.remove(addr) | ||
os.remove(addr[4]) | ||
else: | ||
raise ValueError("%r is not a socket" % addr) | ||
super(UnixSocket, self).__init__(addr, conf, log, fd=fd) | ||
|
@@ -128,12 +122,11 @@ def bind(self, sock): | |
|
||
|
||
def _sock_type(addr): | ||
if isinstance(addr, tuple): | ||
if util.is_ipv6(addr[0]): | ||
sock_type = TCP6Socket | ||
else: | ||
sock_type = TCPSocket | ||
elif isinstance(addr, string_types): | ||
if addr[0] == socket.AF_INET6: | ||
sock_type = TCP6Socket | ||
elif addr[0] == socket.AF_INET: | ||
sock_type = TCPSocket | ||
elif addr[0] == socket.AF_UNIX: | ||
sock_type = UnixSocket | ||
else: | ||
raise TypeError("Unable to create socket from: %r" % addr) | ||
|
@@ -166,7 +159,8 @@ def create_sockets(conf, log, fds=None): | |
for fd in fds: | ||
sock = socket.fromfd(fd, socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock_name = sock.getsockname() | ||
sock_type = _sock_type(sock_name) | ||
sockinfo = (sock.family, sock.type, sock.proto, '', socket.getsockname()) | ||
sock_type = _sock_type(sockinfo) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you pass a tuple here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was done so before. But I can change that. |
||
listener = sock_type(sock_name, conf, log, fd=fd) | ||
listeners.append(listener) | ||
|
||
|
@@ -204,6 +198,7 @@ def create_sockets(conf, log, fds=None): | |
def close_sockets(listeners, unlink=True): | ||
for sock in listeners: | ||
sock_name = sock.getsockname() | ||
socket_family = sock.family | ||
sock.close() | ||
if unlink and _sock_type(sock_name) is UnixSocket: | ||
if unlink and socket_family == socket.AF_UNIX: | ||
os.unlink(sock_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why replacing that code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was described at the beginning. It can handle only one address.