Changeset 1665
- Timestamp:
- 06/16/07 16:25:01
- Files:
-
- trunk/cherrypy/_cpserver.py (modified) (8 diffs)
- 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) (2 diffs)
- trunk/cherrypy/test/webtest.py (modified) (3 diffs)
- trunk/cherrypy/wsgiserver/__init__.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpserver.py
r1660 r1665 29 29 control them all through this object: 30 30 31 s1 = MyWSGIServer(host=' ', port=80)31 s1 = MyWSGIServer(host='0.0.0.0', port=80) 32 32 s2 = another.HTTPServer(host='localhost', SSL=True) 33 cherrypy.server.httpservers = {s1: ('', 80), s2: ('localhost', 443)} 33 cherrypy.server.httpservers = {s1: ('0.0.0.0', 80), 34 s2: ('localhost', 443)} 34 35 # Note we do not use quickstart when we define our own httpservers 35 36 cherrypy.server.start() … … 41 42 42 43 socket_port = 8080 43 socket_host = '' 44 45 _socket_host = 'localhost' 46 def _get_socket_host(self): 47 return self._socket_host 48 def _set_socket_host(self, value): 49 if not value: 50 raise ValueError("Host values of '' or None are not allowed. " 51 "Use '0.0.0.0' instead to listen on all active " 52 "interfaces (INADDR_ANY).") 53 self._socket_host = value 54 socket_host = property(_get_socket_host, _set_socket_host, 55 doc="""The hostname or IP address on which to listen for connections. 56 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.""") 61 44 62 socket_file = '' 45 63 socket_queue_size = 5 … … 106 124 wait_for_free_port(*bind_addr) 107 125 host, port = bind_addr 108 if not host:109 host = '0.0.0.0'110 126 on_what = "%s://%s:%s/" % (scheme, host, port) 111 127 else: … … 157 173 if isinstance(bind_addr, tuple): 158 174 host, port = bind_addr 159 if not host or host == '0.0.0.0': 160 host = socket.gethostname() 175 if host == '0.0.0.0': 176 # 0.0.0.0 is INADDR_ANY, which should answer on localhost. 177 host = 'localhost' 161 178 wait_for_occupied_port(host, port) 162 179 … … 186 203 187 204 host = self.socket_host 188 if not host orhost == '0.0.0.0':189 # The empty string signifies INADDR_ANY. Look up the host name,205 if host == '0.0.0.0': 206 # 0.0.0.0 is INADDR_ANY. Look up the host name, 190 207 # which should be the safest thing to spit out in a URL. 191 208 host = socket.gethostname() … … 208 225 """Raise an error if the given port is not free on the given host.""" 209 226 if not host: 210 # The empty string signifies INADDR_ANY, 211 # which should respond on localhost. 227 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. 212 230 host = 'localhost' 213 231 port = int(port) … … 237 255 """Wait for the specified port to become free (drop requests).""" 238 256 if not host: 239 # The empty string signifies INADDR_ANY, 240 # which should respond on localhost. 257 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. 241 260 host = 'localhost' 242 261 … … 257 276 """Wait for the specified port to become active (receive requests).""" 258 277 if not host: 259 # The empty string signifies INADDR_ANY, 260 # which should respond on localhost. 278 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. 261 281 host = 'localhost' 262 282 trunk/cherrypy/test/test_core.py
r1658 r1665 484 484 485 485 host = self.HOST 486 if not host: 487 # The empty string signifies INADDR_ANY, 488 # which should respond on localhost. 486 if host == '0.0.0.0': 487 # INADDR_ANY, which should respond on localhost. 489 488 host = "127.0.0.1" 490 489 intro = '%s - - [' % host trunk/cherrypy/test/test_proxy.py
r1657 r1665 92 92 port = ":%s" % self.PORT 93 93 host = self.HOST 94 if host == ' ':94 if host == '0.0.0.0': 95 95 import socket 96 96 host = socket.gethostname() trunk/cherrypy/test/test_xmlrpc.py
r1663 r1665 89 89 90 90 self.verbose = verbose 91 92 # Here's where we differ from the superclass. It says: 93 # try: 94 # sock = h._conn.sock 95 # except AttributeError: 96 # sock = None 97 # return self._parse_response(h.getfile(), sock) 98 91 99 return self.parse_response(h.getfile()) 92 100 … … 104 112 pass 105 113 114 host = self.HOST 115 if host == '0.0.0.0': 116 # INADDR_ANY, which should respond on localhost. 117 host = "127.0.0.1" 118 106 119 if scheme == "https": 107 url = 'https://%s:%s/xmlrpc/' % ( self.HOST, self.PORT)120 url = 'https://%s:%s/xmlrpc/' % (host, self.PORT) 108 121 proxy = xmlrpclib.ServerProxy(url, transport=HTTPSTransport()) 109 122 else: 110 url = 'http://%s:%s/xmlrpc/' % ( self.HOST, self.PORT)123 url = 'http://%s:%s/xmlrpc/' % (host, self.PORT) 111 124 proxy = xmlrpclib.ServerProxy(url) 112 125 trunk/cherrypy/test/webtest.py
r1532 r1665 165 165 if on: 166 166 host = self.HOST 167 if not host: 168 # The empty string signifies INADDR_ANY, 169 # which should respond on localhost. 167 if host == '0.0.0.0': 168 # INADDR_ANY, which should respond on localhost. 170 169 host = "127.0.0.1" 171 170 self.HTTP_CONN = cls(host, self.PORT) … … 187 186 188 187 self.url = url 189 host = self.HOST 190 if not host: 191 # The empty string signifies INADDR_ANY, 192 # which should respond on localhost. 193 host = "127.0.0.1" 194 result = openURL(url, headers, method, body, host, self.PORT, 188 result = openURL(url, headers, method, body, self.HOST, self.PORT, 195 189 self.HTTP_CONN, protocol or self.PROTOCOL) 196 190 self.status, self.headers, self.body = result … … 476 470 conn = http_conn 477 471 else: 472 if host == '0.0.0.0': 473 # INADDR_ANY, which should respond on localhost. 474 host = "127.0.0.1" 478 475 conn = http_conn(host, port) 479 476 trunk/cherrypy/wsgiserver/__init__.py
r1660 r1665 730 730 """An HTTP server for WSGI. 731 731 732 bind_addr: a (host, port) tuple if TCP sockets are desired; 733 for UNIX sockets, supply the filename as a string. 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. 738 For UNIX sockets, supply the filename as a string. 734 739 wsgi_app: the WSGI 'application callable'; multiple WSGI applications 735 740 may be passed as (script_name, callable) pairs. … … 761 766 762 767 protocol = "HTTP/1.1" 768 _bind_addr = "localhost" 763 769 version = "CherryPy/3.1alpha" 764 770 ready = False … … 796 802 self.timeout = timeout 797 803 self.shutdown_timeout = shutdown_timeout 804 805 def _get_bind_addr(self): 806 return self._bind_addr 807 def _set_bind_addr(self, value): 808 if isinstance(value, tuple) and value[0] in ('', None): 809 # Despite the socket module docs, using '' does not 810 # allow AI_PASSIVE to work. Passing None instead 811 # returns '0.0.0.0' like we want. In other words: 812 # host AI_PASSIVE result 813 # '' Y 192.168.x.y 814 # '' N 192.168.x.y 815 # None Y 0.0.0.0 816 # None N 127.0.0.1 817 # But since you can get the same effect with an explicit 818 # '0.0.0.0', we deny both the empty string and None as values. 819 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 self._bind_addr = value 823 bind_addr = property(_get_bind_addr, _set_bind_addr, 824 doc="""The interface on which to listen for connections. 825 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. 831 832 For UNIX sockets, supply the filename as a string.""") 798 833 799 834 def start(self): … … 822 857 # Get the correct address family for our host (allows IPv6 addresses) 823 858 host, port = self.bind_addr 824 flags = 0825 if host == '':826 # Despite the socket module docs, using '' does not827 # allow AI_PASSIVE to work. Passing None instead828 # returns '0.0.0.0' like we want. In other words:829 # host AI_PASSIVE result830 # '' Y 192.168.x.y831 # '' N 192.168.x.y832 # None Y 0.0.0.0833 # None N 127.0.0.1834 host = None835 flags = socket.AI_PASSIVE836 859 try: 837 860 info = socket.getaddrinfo(host, port, socket.AF_UNSPEC, 838 socket.SOCK_STREAM, 0, flags)861 socket.SOCK_STREAM, 0, socket.AI_PASSIVE) 839 862 except socket.gaierror: 840 863 # Probably a DNS issue. Assume IPv4. … … 949 972 # here, because we want an actual IP to touch. 950 973 # localhost won't work if we've bound to a public IP, 951 # but it w ould if we bound to INADDR_ANY via host = ''.974 # but it will if we bound to '0.0.0.0' (INADDR_ANY). 952 975 for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, 953 976 socket.SOCK_STREAM):

