Changeset 1225
- Timestamp:
- 08/06/06 21:48:57
- Files:
-
- trunk/cherrypy/__init__.py (modified) (1 diff)
- trunk/cherrypy/_cpengine.py (modified) (3 diffs)
- trunk/cherrypy/_cpmodpy.py (modified) (2 diffs)
- trunk/cherrypy/_cprequest.py (modified) (3 diffs)
- trunk/cherrypy/_cpwsgi.py (modified) (1 diff)
- trunk/cherrypy/lib/cptools.py (modified) (2 diffs)
- trunk/cherrypy/lib/http.py (modified) (1 diff)
- trunk/cherrypy/lib/wsgiapp.py (modified) (1 diff)
- trunk/cherrypy/test/benchmark.py (modified) (1 diff)
- trunk/cherrypy/test/test_core.py (modified) (1 diff)
- trunk/cherrypy/test/test_proxy.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/__init__.py
r1219 r1225 96 96 """Default method for logging access""" 97 97 tmpl = '%(h)s %(l)s %(u)s [%(t)s] "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' 98 s = tmpl % {'h': request.remote _host,98 s = tmpl % {'h': request.remote.name or request.remote.ip, 99 99 'l': '-', 100 100 'u': getattr(request, "login", None) or "-", trunk/cherrypy/_cpengine.py
r1224 r1225 38 38 if _signal_exc.args[0] != "signal only works in main thread": 39 39 raise 40 40 41 41 42 class Engine(object): … … 174 175 " receive requests, False otherwise.") 175 176 176 def request(self, client_address, remote_host, scheme="http"):177 def request(self, local_host, remote_host, scheme="http"): 177 178 """Obtain an HTTP Request object. 178 179 179 client_address: the (IP address, port) of the client 180 remote_host should be the client's host name. If not available 181 (because no reverse DNS lookup is performed), the client 182 IP should be provided. 180 local_host should be an http.Host object with the server info. 181 remote_host should be an http.Host object with the client info. 183 182 scheme: either "http" or "https"; defaults to "http" 184 183 """ … … 196 195 for func in self.on_start_thread_list: 197 196 func(i) 198 r = self.request_class(client_address[0], client_address[1], 199 remote_host, scheme) 197 r = self.request_class(local_host, remote_host, scheme) 200 198 cherrypy.serving.request = r 201 199 cherrypy.serving.response = self.response_class() trunk/cherrypy/_cpmodpy.py
r1224 r1225 4 4 import cherrypy 5 5 from cherrypy._cperror import format_exc, bare_error 6 from cherrypy.lib import http 6 7 7 8 … … 47 48 48 49 # Obtain a Request object from CherryPy 49 clientAddress = req.connection.remote_addr 50 remoteHost = clientAddress[0] 50 local = req.connection.local_addr 51 local = http.Host(local[0], local[1], req.connection.local_host or "") 52 remote = req.connection.remote_addr 53 remote = http.Host(remote[0], remote[1], req.connection.remote_host or "") 54 51 55 scheme = req.parsed_uri[0] or 'http' 52 request = cherrypy.engine.request( clientAddress, remoteHost, scheme)56 request = cherrypy.engine.request(local, remote, scheme) 53 57 req.get_basic_auth_pw() 54 58 request.login = req.user trunk/cherrypy/_cprequest.py
r1224 r1225 53 53 """An HTTP request.""" 54 54 55 # Conversation attributes 56 remote_addr = "localhost" 57 remote_port = 1111 58 remote_host = "localhost" 55 # Conversation/connection attributes 56 local = http.Host("localhost", 80) 57 remote = http.Host("localhost", 1111) 59 58 scheme = "http" 60 59 base = "" … … 91 90 hooks = HookMap(hookpoints) 92 91 93 def __init__(self, remote_addr, remote_port, remote_host, scheme="http"):92 def __init__(self, local_host, remote_host, scheme="http"): 94 93 """Populate a new Request object. 95 94 96 remote_addr should be the client IP address. 97 remote_port should be the client Port. 98 remote_host should be the client's host name. If not available 99 (because no reverse DNS lookup is performed), the client 100 IP should be provided. 95 local_host should be an http.Host object with the server info. 96 remote_host should be an http.Host object with the client info. 101 97 scheme should be a string, either "http" or "https". 102 98 """ 103 self.remote_addr = remote_addr 104 self.remote_port = remote_port 105 self.remote_host = remote_host 99 self.local = local_host 100 self.remote = remote_host 106 101 self.scheme = scheme 107 102 … … 272 267 host = dict.__getitem__(headers, 'Host') 273 268 if not host: 274 host = cherrypy.config.get('server.socket_host', '')269 host = self.local.name or self.local.ip 275 270 self.base = "%s://%s" % (self.scheme, host) 276 271 trunk/cherrypy/_cpwsgi.py
r1224 r1225 31 31 try: 32 32 env = environ.get 33 clientAddr = (env('REMOTE_ADDR', ''), int(env('REMOTE_PORT', -1))) 34 request = cherrypy.engine.request(clientAddr, env('REMOTE_ADDR', ''), 35 environ['wsgi.url_scheme']) 33 local = http.Host('', int(env('SERVER_PORT', 80)), 34 env('SERVER_NAME', '')) 35 remote = http.Host(env('REMOTE_ADDR', ''), 36 int(env('REMOTE_PORT', -1)), 37 env('REMOTE_HOST', '')) 38 request = cherrypy.engine.request(local, remote, env('wsgi.url_scheme')) 36 39 37 40 # LOGON_USER is served by IIS, and is the name of the trunk/cherrypy/lib/cptools.py
r1222 r1225 76 76 77 77 if base is None: 78 port = str(cherrypy.config.get('server.socket_port', '80'))79 if port == "80":78 port = cherrypy.local.port 79 if port == 80: 80 80 base = 'http://localhost' 81 81 else: … … 97 97 # See http://bob.pythonmac.org/archives/2005/09/23/apache-x-forwarded-for-caveat/ 98 98 xff = xff.split(',')[-1].strip() 99 request.remote _host= xff99 request.remote.name = xff 100 100 101 101 trunk/cherrypy/lib/http.py
r1224 r1225 438 438 return data 439 439 440 441 class Host(object): 442 """An internet address. 443 444 name should be the client's host name. If not available (because no DNS 445 lookup is performed), the IP address should be used instead. 446 """ 447 448 ip = "0.0.0.0" 449 port = 80 450 name = "unknown.tld" 451 452 def __init__(self, ip, port, name=None): 453 self.ip = ip 454 self.port = port 455 if name is None: 456 name = ip 457 self.name = name trunk/cherrypy/lib/wsgiapp.py
r1224 r1225 32 32 environ["QUERY_STRING"] = cherrypy.request.query_string 33 33 environ["SERVER_PROTOCOL"] = cherrypy.request.protocol 34 server_name = getattr(cherrypy.server.httpserver, 'server_name', "None") 35 environ["SERVER_NAME"] = server_name 36 environ["SERVER_PORT"] = cherrypy.config.get('server.socket_port') 37 environ["REMOTE_HOST"] = cherrypy.request.remote_host 38 environ["REMOTE_ADDR"] = cherrypy.request.remote_addr 39 environ["REMOTE_PORT"] = cherrypy.request.remote_port 34 environ["SERVER_NAME"] = cherrypy.request.local.name 35 environ["SERVER_PORT"] = cherrypy.request.local.port 36 environ["REMOTE_HOST"] = cherrypy.request.remote.name 37 environ["REMOTE_ADDR"] = cherrypy.request.remote.ip 38 environ["REMOTE_PORT"] = cherrypy.request.remote.port 40 39 # then all the http headers 41 40 headers = cherrypy.request.headers trunk/cherrypy/test/benchmark.py
r1224 r1225 82 82 """A null HTTP request class, returning 204 and an empty body.""" 83 83 84 def __init__(self, remote_addr, remote_port, remote_host, scheme="http"):84 def __init__(self, local, remote, scheme="http"): 85 85 pass 86 86 trunk/cherrypy/test/test_core.py
r1222 r1225 276 276 hMap['server'] = 'CherryPy headertest' 277 277 hMap['location'] = ('%s://127.0.0.1:%s/headers/' 278 % (cherrypy.request.remote _port,278 % (cherrypy.request.remote.port, 279 279 cherrypy.request.scheme)) 280 280 trunk/cherrypy/test/test_proxy.py
r1171 r1225 12 12 13 13 def remotehost(self): 14 return cherrypy.request.remote _host14 return cherrypy.request.remote.name 15 15 remotehost.exposed = True 16 16

