Changeset 1666
- Timestamp:
- 06/16/07 16:58:53
- Files:
-
- trunk/cherrypy/_cpserver.py (modified) (7 diffs)
- trunk/cherrypy/test/helper.py (modified) (1 diff)
- trunk/cherrypy/test/test_core.py (modified) (1 diff)
- trunk/cherrypy/test/test_proxy.py (modified) (1 diff)
- trunk/cherrypy/test/test_xmlrpc.py (modified) (1 diff)
- trunk/cherrypy/test/webtest.py (modified) (2 diffs)
- trunk/cherrypy/wsgiserver/__init__.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpserver.py
r1665 r1666 7 7 import cherrypy 8 8 from cherrypy.lib import attributes 9 10 11 def client_host(server_host): 12 """Return the host on which a client can connect to the given listener.""" 13 if server_host == '0.0.0.0': 14 # 0.0.0.0 is INADDR_ANY, which should answer on localhost. 15 return '127.0.0.1' 16 if server_host == '::': 17 # :: is IN6ADDR_ANY, which should answer on localhost. 18 return '::1' 19 return server_host 9 20 10 21 … … 55 66 doc="""The hostname or IP address on which to listen for connections. 56 67 57 Valid host values include any IPv4 or IPv6 address, any valid 58 hostname, 'localhost' as a synonym for '127.0.0.1', and '0.0.0.0' 59 as a special entry meaning "all active interfaces" (INADDR_ANY). 60 The empty string or None are not allowed.""") 68 Host values may be any IPv4 or IPv6 address, or any valid hostname. 69 The string 'localhost' is a synonym for '127.0.0.1' (or '::1', if 70 your hosts file prefers IPv6). The string '0.0.0.0' is a special 71 IPv4 entry meaning "any active interface" (INADDR_ANY), and '::' 72 is the similar IN6ADDR_ANY for IPv6. The empty string or None are 73 not allowed.""") 61 74 62 75 socket_file = '' … … 173 186 if isinstance(bind_addr, tuple): 174 187 host, port = bind_addr 175 if host == '0.0.0.0':176 # 0.0.0.0 is INADDR_ANY, which should answer on localhost.177 host = 'localhost'178 188 wait_for_occupied_port(host, port) 179 189 … … 203 213 204 214 host = self.socket_host 205 if host == '0.0.0.0': 206 # 0.0.0.0 is INADDR_ANY. Look up the host name, 207 # which should be the safest thing to spit out in a URL. 215 if host in ('0.0.0.0', '::'): 216 # 0.0.0.0 is INADDR_ANY and :: is IN6ADDR_ANY. 217 # Look up the host name, which should be the 218 # safest thing to spit out in a URL. 208 219 host = socket.gethostname() 209 220 … … 226 237 if not host: 227 238 raise ValueError("Host values of '' or None are not allowed.") 228 if host == '0.0.0.0': 229 # 0.0.0.0 is INADDR_ANY, which should answer on localhost. 230 host = 'localhost' 239 host = client_host(host) 231 240 port = int(port) 232 241 … … 256 265 if not host: 257 266 raise ValueError("Host values of '' or None are not allowed.") 258 if host == '0.0.0.0':259 # 0.0.0.0 is INADDR_ANY, which should answer on localhost.260 host = 'localhost'261 267 262 268 for trial in xrange(50): … … 277 283 if not host: 278 284 raise ValueError("Host values of '' or None are not allowed.") 279 if host == '0.0.0.0':280 # 0.0.0.0 is INADDR_ANY, which should answer on localhost.281 host = 'localhost'282 285 283 286 for trial in xrange(50): trunk/cherrypy/test/helper.py
r1627 r1666 43 43 port = ":%s" % self.PORT 44 44 45 host = self.HOST 46 if not host: 47 # The empty string signifies INADDR_ANY, 48 # which should respond on localhost. 49 host = "127.0.0.1" 50 51 return "%s://%s%s%s" % (self.scheme, host, port, 45 return "%s://%s%s%s" % (self.scheme, self.HOST, port, 52 46 self.script_name.rstrip("/")) 53 47 trunk/cherrypy/test/test_core.py
r1665 r1666 487 487 # INADDR_ANY, which should respond on localhost. 488 488 host = "127.0.0.1" 489 if host == '::': 490 # IN6ADDR_ANY, which should respond on localhost. 491 host = "::1" 489 492 intro = '%s - - [' % host 490 493 trunk/cherrypy/test/test_proxy.py
r1665 r1666 92 92 port = ":%s" % self.PORT 93 93 host = self.HOST 94 if host == '0.0.0.0':94 if host in ('0.0.0.0', '::'): 95 95 import socket 96 96 host = socket.gethostname() trunk/cherrypy/test/test_xmlrpc.py
r1665 r1666 116 116 # INADDR_ANY, which should respond on localhost. 117 117 host = "127.0.0.1" 118 if host == '::': 119 # IN6ADDR_ANY, which should respond on localhost. 120 host = "::1" 118 121 119 122 if scheme == "https": trunk/cherrypy/test/webtest.py
r1665 r1666 168 168 # INADDR_ANY, which should respond on localhost. 169 169 host = "127.0.0.1" 170 elif host == '::': 171 # IN6ADDR_ANY, which should respond on localhost. 172 host = "::1" 170 173 self.HTTP_CONN = cls(host, self.PORT) 171 174 # Automatically re-connect? … … 473 476 # INADDR_ANY, which should respond on localhost. 474 477 host = "127.0.0.1" 478 elif host == '::': 479 # IN6ADDR_ANY, which should respond on localhost. 480 host = "::1" 475 481 conn = http_conn(host, port) 476 482 trunk/cherrypy/wsgiserver/__init__.py
r1665 r1666 731 731 732 732 bind_addr: The interface on which to listen for connections. 733 For TCP sockets, a (host, port) tuple. Valid host values include: 734 any IPv4 or IPv6 address, any valid hostname, 'localhost' as a 735 synonym for '127.0.0.1', and '0.0.0.0' as a special entry meaning 736 "all active interfaces" (INADDR_ANY). The empty string or None 737 are not allowed. 733 For TCP sockets, a (host, port) tuple. Host values may be any IPv4 734 or IPv6 address, or any valid hostname. The string 'localhost' is a 735 synonym for '127.0.0.1' (or '::1', if your hosts file prefers IPv6). 736 The string '0.0.0.0' is a special IPv4 entry meaning "any active 737 interface" (INADDR_ANY), and '::' is the similar IN6ADDR_ANY for 738 IPv6. The empty string or None are not allowed. 739 738 740 For UNIX sockets, supply the filename as a string. 739 741 wsgi_app: the WSGI 'application callable'; multiple WSGI applications … … 818 820 # '0.0.0.0', we deny both the empty string and None as values. 819 821 raise ValueError("Host values of '' or None are not allowed. " 820 "Use '0.0.0.0' instead to listen on all active"821 " interfaces (INADDR_ANY).")822 "Use '0.0.0.0' (IPv4) or '::' (IPv6) instead " 823 "to listen on all active interfaces.") 822 824 self._bind_addr = value 823 825 bind_addr = property(_get_bind_addr, _set_bind_addr, 824 826 doc="""The interface on which to listen for connections. 825 827 826 For TCP sockets, a (host, port) tuple. Valid host values include: 827 any IPv4 or IPv6 address, any valid hostname, 'localhost' as a 828 synonym for '127.0.0.1', and '0.0.0.0' as a special entry meaning 829 "all active interfaces" (INADDR_ANY). The empty string or None 830 are not allowed. 828 For TCP sockets, a (host, port) tuple. Host values may be any IPv4 829 or IPv6 address, or any valid hostname. The string 'localhost' is a 830 synonym for '127.0.0.1' (or '::1', if your hosts file prefers IPv6). 831 The string '0.0.0.0' is a special IPv4 entry meaning "any active 832 interface" (INADDR_ANY), and '::' is the similar IN6ADDR_ANY for 833 IPv6. The empty string or None are not allowed. 831 834 832 835 For UNIX sockets, supply the filename as a string.""")

