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

Changeset 896

Show
Ignore:
Timestamp:
12/29/05 17:03:46
Author:
fumanchu
Message:

Fix for #404, #417 (index files and staticfilter). New "static_filter.index" config entry.

Files:

Legend:

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

    r895 r896  
    3434            extraPath = extraPath.lstrip(r"\/") 
    3535            extraPath = urllib.unquote(extraPath) 
     36            # If extraPath is "", filename will end in a slash 
    3637            filename = os.path.join(staticDir, extraPath) 
    3738         
    3839        # If filename is relative, make absolute using "root". 
     40        # Note that, if "root" isn't defined, we still may send 
     41        # a relative path to serveFile. 
    3942        if not os.path.isabs(filename): 
    4043            root = config.get('static_filter.root', '').rstrip(r"\/") 
     
    4649            request.execute_main = False 
    4750        except cherrypy.NotFound: 
    48             # if we didn't find the static file, continue 
    49             # handling the request. we might find a dynamic 
    50             # handler instead. 
    51             pass 
     51            # If we didn't find the static file, continue handling the 
     52            # request. We might find a dynamic handler instead. 
     53             
     54            # But first check for an index file if a folder was requested. 
     55            if filename[-1:] in ("/", "\\"): 
     56                idx = config.get('static_filter.index', '') 
     57                if idx: 
     58                    try: 
     59                        cptools.serveFile(os.path.join(filename, idx)) 
     60                        request.execute_main = False 
     61                    except cherrypy.NotFound: 
     62                        pass 
    5263 
  • trunk/cherrypy/lib/cptools.py

    r856 r896  
    9393        if cherrypy.config.get('server.log_file_not_found', False): 
    9494            cherrypy.log("    NOT FOUND file: %s" % path, "DEBUG") 
     95        raise cherrypy.NotFound() 
     96     
     97    if os.path.isdir(path): 
     98        # Let the caller deal with it as they like. 
    9599        raise cherrypy.NotFound() 
    96100     
  • trunk/cherrypy/test/test_static_filter.py

    r895 r896  
    22test.prefer_parent_path() 
    33 
     4import os 
     5curdir = os.path.join(os.getcwd(), os.path.dirname(__file__)) 
     6 
    47import cherrypy 
    5 import o
     8from cherrypy.lib import cptool
    69 
    710 
    8 class Root: pass 
     11class Root: 
     12    pass 
    913 
    1014class Static: 
     15     
     16    def index(self): 
     17        return 'You want the Baron? You can have the Baron!' 
     18    index.exposed = True 
    1119     
    1220    def dynamic(self): 
     
    3442    '/docroot': { 
    3543        'static_filter.on': True, 
    36         'static_filter.root': os.path.join(os.getcwd(), os.path.dirname(__file__))
     44        'static_filter.root': curdir
    3745        'static_filter.dir': 'static', 
     46        'static_filter.index': 'index.html', 
    3847    }, 
    3948}) 
     
    7180        self.assertMatchesBody('^Dummy stylesheet') 
    7281         
    73         # Check a directory (should currently fail--no provision for it) 
    74         ignore = helper.webtest.ignored_exceptions 
    75         ignore.append(IOError) 
    76         try: 
    77             self.getPage("/static/") 
    78             self.assertErrorPage(500) 
    79         finally: 
    80             ignore.pop() 
    81          
    8282        # Test that NotFound will then try dynamic handlers (see [878]). 
    8383        self.getPage("/static/dynamic") 
    8484        self.assertBody("This is a DYNAMIC page") 
     85         
     86        # Check a directory via fall-through to dynamic handler. 
     87        self.getPage("/static/") 
     88        self.assertStatus('200 OK') 
     89        self.assertHeader('Content-Type', 'text/html') 
     90        self.assertBody('You want the Baron? You can have the Baron!') 
     91         
     92        # Check a directory via "static_filter.index". 
     93        self.getPage("/docroot/") 
     94        self.assertStatus('200 OK') 
     95        self.assertHeader('Content-Type', 'text/html') 
     96        self.assertBody('Hello, world\r\n') 
     97        # The same page should be returned even if redirected. 
     98        self.getPage("/docroot") 
     99        self.assertStatus('200 OK') 
     100        self.assertHeader('Content-Type', 'text/html') 
     101        self.assertBody('Hello, world\r\n') 
    85102 
    86103 

Hosted by WebFaction

Log in as guest/cpguest to create tickets