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

Changeset 522

Show
Ignore:
Timestamp:
08/09/05 16:00:58
Author:
fumanchu
Message:

1. Config section [global] (pathless) is now distinct from / (root path); they are no longer synonyms. "global" is the parent of "/".
2. The Request-URI is now parsed much earlier in Request processing, so that onStartResource and error filter methods may have access to it.
3. Absolute URI's (on the request line) are now converted to relative URI's to facilitate configMap lookups.
4. A Request-URI of "*" sets cherrypy.request.path to "global" (again for configMap).
5. Fixed a bug in config.getAll where the initial slash was missing for configMap lookups.
6. Bugfix: del Content-Length header if None.

Files:

Legend:

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

    r501 r522  
    3333import urllib, os, sys, time, types, cgi, re 
    3434import mimetypes, Cookie 
     35from urlparse import urlparse 
    3536 
    3637import cherrypy 
     
    204205        """ 
    205206         
    206         self.requestLine = requestLine 
     207        cherrypy.request.method = "" 
     208        cherrypy.request.requestLine = requestLine.strip() 
     209        self.parseFirstLine() 
     210         
    207211        self.requestHeaders = headers 
    208212         
     
    212216        cherrypy.request.paramList = [] # Only used for Xml-Rpc 
    213217        cherrypy.request.headerMap = {} 
    214         cherrypy.request.requestLine = requestLine 
    215218        cherrypy.request.simpleCookie = Cookie.SimpleCookie() 
    216219        cherrypy.request.rfile = rfile 
    217220        cherrypy.request.scheme = scheme 
    218         cherrypy.request.method = "" 
    219221         
    220222        # Prepare cherrypy.response variables 
     
    273275            handleError(sys.exc_info()) 
    274276     
     277    def parseFirstLine(self): 
     278        # This has to be done very early in the request process, 
     279        # because request.path is used for config lookups right away. 
     280        req = cherrypy.request 
     281         
     282        # Parse first line 
     283        req.method, path, req.protocol = req.requestLine.split() 
     284        req.processRequestBody = req.method in ("POST", "PUT") 
     285         
     286        # separate the queryString, or set it to "" if not found 
     287        if "?" in path: 
     288            path, req.queryString = path.split("?", 1) 
     289        else: 
     290            path, req.queryString = path, "" 
     291         
     292        # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2 
     293        if path == "*": 
     294            path = "global" 
     295        elif not path.startswith("/"): 
     296            # path is an absolute path (including "http://host.domain.tld"); 
     297            # convert it to a relative path, so configMap lookups work. This 
     298            # default method assumes all hosts are valid for this server. 
     299            scheme, location, p, pm, q, f = urlparse(path) 
     300            path = path[len(scheme + "://" + location):] 
     301         
     302        # Save original value (in case it gets modified by filters) 
     303        req.path = req.originalPath = path 
     304     
    275305    def processRequestHeaders(self): 
    276306        req = cherrypy.request 
    277          
    278         # Parse first line 
    279         req.method, path, req.protocol = self.requestLine.split() 
    280         req.processRequestBody = req.method in ("POST", "PUT") 
    281307         
    282308        # Compare request and server HTTP versions, in case our server does 
     
    297323        cherrypy.request.version = min(request_v, server_v) 
    298324         
    299         # find the queryString, or set it to "" if not found 
    300         if "?" in path: 
    301             req.path, req.queryString = path.split("?", 1) 
    302         else: 
    303             req.path, req.queryString = path, "" 
    304          
    305325        # build a paramMap dictionary from queryString 
    306326        pm = cgi.parse_qs(req.queryString, keep_blank_values=True) 
     
    324344                req.simpleCookie.load(value) 
    325345         
    326         msg = "%s - %s" % (req.remoteAddr, self.requestLine.strip()
     346        msg = "%s - %s" % (req.remoteAddr, req.requestLine
    327347        cherrypy.log(msg, "HTTP") 
    328348         
     
    332352         
    333353        # Save original values (in case they get modified by filters) 
    334         req.originalPath = req.path 
    335354        req.originalParamMap = req.paramMap 
    336355        req.originalParamList = req.paramList 
     
    346365                raise cherrypy.RequestHandled 
    347366        req.base = "%s://%s" % (req.scheme, req.headerMap.get('Host', '')) 
    348         req.browserUrl = req.base + path 
     367        req.browserUrl = req.base + req.path 
    349368     
    350369    def processRequestBody(self): 
     
    547566            cherrypy.response.body = [content] 
    548567            cherrypy.response.headerMap['Content-Length'] = len(content) 
     568        else: 
     569            del cherrypy.response.headerMap['Content-Length'] 
    549570     
    550571    # For some statuses, Internet Explorer 5+ shows "friendly error messages" 
  • trunk/cherrypy/_cputil.py

    r521 r522  
    248248    # Avoid pollution of the system path 
    249249    for path in filtersRoot: 
    250         sys.path.remove(path)    
     250        sys.path.remove(path) 
    251251 
    252252 
  • trunk/cherrypy/config.py

    r483 r522  
    4747    'server.socketFile': '', 
    4848    'server.socketQueueSize': 5, 
    49  
     49     
    5050    'server.environment': 'development', 
    5151    'server.protocolVersion': 'HTTP/1.0', 
     
    9191        path = cherrypy.request.path 
    9292    except AttributeError: 
    93         path = "/" 
     93        # There's no request.path yet, so use the global settings. 
     94        path = "global" 
    9495     
    9596    while True: 
    9697        if path == "": 
    9798            path = "/" 
     99         
    98100        try: 
    99101            result = configMap[path][key] 
    100102        except KeyError: 
    101             if path not in ("/", "global"): 
    102                 i = path.rfind("/") 
    103                 if i < 0: 
    104                     result = defaultValue 
    105                 else: 
    106                     path = path[:i] 
    107                     continue 
    108             elif path != "global": 
     103            if path == "global": 
     104                result = defaultValue 
     105            elif path == "/": 
    109106                path = "global" 
    110107                continue 
    111108            else: 
    112                 result = defaultValue 
     109                path = path[:path.rfind("/")] 
     110                continue 
    113111        break 
    114112     
    115113    if returnSection: 
    116         if path == 'global': 
    117             return '/' 
    118114        return path 
    119115    else: 
     
    128124     
    129125    try: 
     126        results = [('global', configMap['global'][key])] 
     127    except KeyError: 
     128        results = [] 
     129     
     130    try: 
    130131        path = cherrypy.request.path 
    131132    except AttributeError: 
    132         path = "/" 
    133      
    134     pathList = cherrypy.request.path.split('/') 
    135      
    136     results = [] 
    137      
    138     try: 
    139         results = [('/',  configMap['global'][key])] 
    140     except KeyError: 
    141         pass 
    142      
    143     if path == '/': 
    144133        return results 
    145134     
     135    pathList = path.split('/') 
     136     
    146137    for n in xrange(1, len(pathList)): 
    147         path = '/'.join(pathList[0:n+1]) 
     138        path = '/' + '/'.join(pathList[0:n+1]) 
    148139        try: 
    149140            results.append((path, configMap[path][key])) 
    150141        except KeyError: 
    151142            pass 
    152  
     143     
    153144    return results 
    154         
     145 
    155146 
    156147class CaseSensitiveConfigParser(ConfigParser.ConfigParser): 
  • trunk/cherrypy/lib/covercp.py

    r493 r522  
    159159    import cherrypy 
    160160    cherrypy.root = CoverStats() 
    161     cherrypy.config.update({'global': {'server.socketPort': port, 
    162                                        'server.threadPool': 10, 
    163                                        'server.environment': "production", 
    164                                        'session.storageType': "ram", 
    165                                        } 
     161    cherrypy.config.update({'server.socketPort': port, 
     162                            'server.threadPool': 10, 
     163                            'server.environment': "production", 
     164                            'session.storageType': "ram", 
    166165                            }) 
    167166    cherrypy.server.start() 
  • trunk/cherrypy/lib/profiler.py

    r405 r522  
    140140    import cherrypy 
    141141    cherrypy.root = Profiler(path) 
    142     cherrypy.config.update({'global': {'server.socketPort': port, 
    143                                        'server.threadPool': 10, 
    144                                        'server.environment': "production", 
    145                                        'session.storageType': "ram", 
    146                                        } 
     142    cherrypy.config.update({'server.socketPort': port, 
     143                            'server.threadPool': 10, 
     144                            'server.environment': "production", 
     145                            'session.storageType': "ram", 
    147146                            }) 
    148147    cherrypy.server.start() 
  • trunk/cherrypy/test/test.py

    r495 r522  
    244244         
    245245        if conf is None: 
    246             conf = {'global': {'server.socketHost': '127.0.0.1', 
    247                                'server.socketPort': 8000, 
    248                                'server.threadPool': 10, 
    249                                'server.logToScreen': False, 
    250                                'server.environment': "production", 
    251                                } 
     246            conf = {'server.socketHost': '127.0.0.1', 
     247                    'server.socketPort': 8000, 
     248                    'server.threadPool': 10, 
     249                    'server.logToScreen': False, 
     250                    'server.environment': "production", 
    252251                    } 
    253252        elif isinstance(conf, basestring): 
  • trunk/cherrypy/test/test_baseurl_filter.py

    r474 r522  
    3838cherrypy.root = Root() 
    3939cherrypy.config.update({ 
    40     'global': { 
    4140        'server.environment': 'production', 
    4241        'server.logToScreen': False, 
    4342        'baseUrlFilter.on': True, 
    4443        'baseUrlFilter.baseUrl': 'http://www.mydomain.com' 
    45     } 
    4644}) 
    4745 
  • trunk/cherrypy/test/test_cache_filter.py

    r474 r522  
    4343cherrypy.root = Root() 
    4444cherrypy.config.update({ 
    45     'global': { 
    4645        'server.logToScreen': False, 
    4746        'server.environment': 'production', 
    4847        'cacheFilter.on': True, 
    49     } 
    5048}) 
    5149 
  • trunk/cherrypy/test/test_combinedfilters.py

    r474 r522  
    4141cherrypy.root = Root() 
    4242cherrypy.config.update({ 
    43     'global': { 
    4443        'server.logToScreen': False, 
    4544        'server.environment': 'production', 
    4645        'gzipFilter.on': True, 
    4746        'encodingFilter.on': True, 
    48     } 
    4947}) 
    5048 
  • trunk/cherrypy/test/test_core.py

    r509 r522  
    219219 
    220220cherrypy.config.update({ 
    221     'global': { 
    222         'server.logToScreen': False, 
    223         'server.environment': 'production', 
     221    'global': {'server.logToScreen': False, 
     222               'server.environment': 'production', 
     223               }, 
     224    '/': { 
    224225        'foo': 'this', 
    225226        'bar': 'that', 
     
    235236}) 
    236237 
     238# Shortcut syntax--should get put in the "global" bucket 
     239cherrypy.config.update({'luxuryyacht': 'throatwobblermangrove'}) 
     240 
    237241import helper 
    238242import os 
     
    241245     
    242246    def testConfig(self): 
     247        self.assertEqual(cherrypy.config.configMap["global"]["luxuryyacht"], 
     248                         'throatwobblermangrove') 
     249         
    243250        tests = [ 
    244251            ('/',        'nex', None   ), 
  • trunk/cherrypy/test/test_decodingencoding_filter.py

    r474 r522  
    3838cherrypy.root = Root() 
    3939cherrypy.config.update({ 
    40     'global': { 
    4140        'server.logToScreen': False, 
    4241        'server.environment': 'production', 
    4342        'encodingFilter.on': True, 
    4443        'decodingFilter.on': True 
    45     } 
    4644}) 
    4745 
  • trunk/cherrypy/test/test_gzip_filter.py

    r482 r522  
    4444cherrypy.root = Root() 
    4545cherrypy.config.update({ 
    46     'global': { 
    4746        'server.logToScreen': False, 
    4847        'server.environment': 'production', 
    4948        'gzipFilter.on': True, 
    50     } 
    5149}) 
    5250 
  • trunk/cherrypy/test/test_logdebuginfo_filter.py

    r474 r522  
    3636cherrypy.root = Root() 
    3737cherrypy.config.update({ 
    38     'global': { 
    3938        'session.storageType': 'ram', 
    4039        'session.timeout': 60, 
     
    4645        'server.environment': 'production', 
    4746        'logDebugInfoFilter.on': True, 
    48     } 
    4947}) 
    5048 
  • trunk/cherrypy/test/test_objectmapping.py

    r495 r522  
    9494cherrypy.root.dir1.dir2.dir3.dir4 = Dir4() 
    9595cherrypy.config.update({ 
    96     'global': { 
    9796        'server.logToScreen': False, 
    9897        'server.environment': "production", 
    99     } 
    10098}) 
    10199 
  • trunk/cherrypy/test/test_tutorials.py

    r495 r522  
    3939        """Import or reload tutorial module as needed.""" 
    4040        cherrypy.config.reset() 
    41         cherrypy.config.update({'global': {'server.socketHost': self.HOST, 
    42                                            'server.socketPort': self.PORT, 
    43                                            'server.threadPool': 10, 
    44                                            'server.logToScreen': False, 
    45                                            'server.environment': "production", 
    46                                            }}) 
     41        cherrypy.config.update({'server.socketHost': self.HOST, 
     42                                'server.socketPort': self.PORT, 
     43                                'server.threadPool': 10, 
     44                                'server.logToScreen': False, 
     45                                'server.environment': "production", 
     46                                }) 
    4747         
    4848        target = "cherrypy.tutorial." + tutorialName 
     
    125125    def test07Sessions(self): 
    126126        self.load_tut_module("tut07_sessions") 
    127         cherrypy.config.update({"global": {"sessionFilter.on": True}}) 
     127        cherrypy.config.update({"sessionFilter.on": True}) 
    128128         
    129129        self.getPage('/') 
     
    139139    def test08AdvancedSessions(self): 
    140140        self.load_tut_module("tut08_advanced_sessions") 
    141         cherrypy.config.update({"global": {"sessionFilter.on": True}}) 
     141        cherrypy.config.update({"sessionFilter.on": True}) 
    142142         
    143143        self.getPage('/') 
  • trunk/cherrypy/test/test_virtualhost_filter.py

    r474 r522  
    3636cherrypy.root = Root() 
    3737cherrypy.config.update({ 
    38     'global': { 
    3938        'server.logToScreen': False, 
    4039        'server.environment': 'production', 
    4140        'virtualHostFilter.on': True, 
    4241        'virtualHostFilter.prefix': '/index2', 
    43     }, 
    4442}) 
    4543 
  • trunk/cherrypy/tutorial/tut07_sessions.py

    r444 r522  
    2929 
    3030cherrypy.root = HitCounter() 
    31 cherrypy.config.update({'global': {'sessionFilter.on': True}}) 
     31cherrypy.config.update({'sessionFilter.on': True}) 
    3232 
    3333if __name__ == '__main__': 

Hosted by WebFaction

Log in as guest/cpguest to create tickets