Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1225

Show
Ignore:
Timestamp:
08/06/06 21:48:57
Author:
fumanchu
Message:

Replaced request.remote_addr, remote_port, and remote_host with a single "remote" attribute, an instance of lib.http.Host, which has "ip", "port" and "name" attributes. Added a similar request.local attribute. Changed request() signature to (local, remote, scheme). This allows requests run behind multiple HTTP servers to know the address info for their particular connection.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/__init__.py

    r1219 r1225  
    9696    """Default method for logging access""" 
    9797    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
    9999                'l': '-', 
    100100                'u': getattr(request, "login", None) or "-", 
  • trunk/cherrypy/_cpengine.py

    r1224 r1225  
    3838    if _signal_exc.args[0] != "signal only works in main thread": 
    3939        raise 
     40 
    4041 
    4142class Engine(object): 
     
    174175                                    " receive requests, False otherwise.") 
    175176     
    176     def request(self, client_address, remote_host, scheme="http"): 
     177    def request(self, local_host, remote_host, scheme="http"): 
    177178        """Obtain an HTTP Request object. 
    178179         
    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. 
    183182        scheme: either "http" or "https"; defaults to "http" 
    184183        """ 
     
    196195                for func in self.on_start_thread_list: 
    197196                    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) 
    200198        cherrypy.serving.request = r 
    201199        cherrypy.serving.response = self.response_class() 
  • trunk/cherrypy/_cpmodpy.py

    r1224 r1225  
    44import cherrypy 
    55from cherrypy._cperror import format_exc, bare_error 
     6from cherrypy.lib import http 
    67 
    78 
     
    4748         
    4849        # 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         
    5155        scheme = req.parsed_uri[0] or 'http' 
    52         request = cherrypy.engine.request(clientAddress, remoteHost, scheme) 
     56        request = cherrypy.engine.request(local, remote, scheme) 
    5357        req.get_basic_auth_pw() 
    5458        request.login = req.user 
  • trunk/cherrypy/_cprequest.py

    r1224 r1225  
    5353    """An HTTP request.""" 
    5454     
    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) 
    5958    scheme = "http" 
    6059    base = "" 
     
    9190    hooks = HookMap(hookpoints) 
    9291     
    93     def __init__(self, remote_addr, remote_port, remote_host, scheme="http"): 
     92    def __init__(self, local_host, remote_host, scheme="http"): 
    9493        """Populate a new Request object. 
    9594         
    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. 
    10197        scheme should be a string, either "http" or "https". 
    10298        """ 
    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 
    106101        self.scheme = scheme 
    107102         
     
    272267        host = dict.__getitem__(headers, 'Host') 
    273268        if not host: 
    274             host = cherrypy.config.get('server.socket_host', '') 
     269            host = self.local.name or self.local.ip 
    275270        self.base = "%s://%s" % (self.scheme, host) 
    276271     
  • trunk/cherrypy/_cpwsgi.py

    r1224 r1225  
    3131    try: 
    3232        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')) 
    3639         
    3740        # LOGON_USER is served by IIS, and is the name of the 
  • trunk/cherrypy/lib/cptools.py

    r1222 r1225  
    7676     
    7777    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
    8080            base = 'http://localhost' 
    8181        else: 
     
    9797                # See http://bob.pythonmac.org/archives/2005/09/23/apache-x-forwarded-for-caveat/ 
    9898                xff = xff.split(',')[-1].strip() 
    99             request.remote_host = xff 
     99            request.remote.name = xff 
    100100 
    101101 
  • trunk/cherrypy/lib/http.py

    r1224 r1225  
    438438        return data 
    439439 
     440 
     441class 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  
    3232    environ["QUERY_STRING"] = cherrypy.request.query_string 
    3333    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 
    4039    # then all the http headers 
    4140    headers = cherrypy.request.headers 
  • trunk/cherrypy/test/benchmark.py

    r1224 r1225  
    8282    """A null HTTP request class, returning 204 and an empty body.""" 
    8383     
    84     def __init__(self, remote_addr, remote_port, remote_host, scheme="http"): 
     84    def __init__(self, local, remote, scheme="http"): 
    8585        pass 
    8686     
  • trunk/cherrypy/test/test_core.py

    r1222 r1225  
    276276            hMap['server'] = 'CherryPy headertest' 
    277277            hMap['location'] = ('%s://127.0.0.1:%s/headers/' 
    278                                 % (cherrypy.request.remote_port, 
     278                                % (cherrypy.request.remote.port, 
    279279                                   cherrypy.request.scheme)) 
    280280             
  • trunk/cherrypy/test/test_proxy.py

    r1171 r1225  
    1212         
    1313        def remotehost(self): 
    14             return cherrypy.request.remote_host 
     14            return cherrypy.request.remote.name 
    1515        remotehost.exposed = True 
    1616         

Hosted by WebFaction

Log in as guest/cpguest to create tickets