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

Changeset 1470

Show
Ignore:
Timestamp:
12/03/06 05:31:25
Author:
fumanchu
Message:

Fix for #614 (VirtualHost? and staticdir tool still don't play well together).

Files:

Legend:

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

    r1467 r1470  
    350350            path_info = http.urljoin(prefix, path_info) 
    351351         
    352         return next_dispatcher(path_info) 
     352        result = next_dispatcher(path_info) 
     353         
     354        # Touch up staticdir config. See http://www.cherrypy.org/ticket/614. 
     355        section = cherrypy.request.config.get('tools.staticdir.section') 
     356        if section: 
     357            section = section[len(prefix):] 
     358            cherrypy.request.config['tools.staticdir.section'] = section 
     359         
     360        return result 
    353361    return vhost_dispatch 
    354362 
  • trunk/cherrypy/_cprequest.py

    r1469 r1470  
    179179                  "response": response_namespace, 
    180180                  "error_page": error_page_namespace, 
     181                  # "tools": See _cptools.Toolbox 
    181182                  } 
    182183     
  • trunk/cherrypy/test/test_virtualhost.py

    r1453 r1470  
    66 
    77import cherrypy 
    8 from cherrypy import _cpdispatch 
    98 
    109def setup_server(): 
     
    3837        url.exposed = True 
    3938         
     39        # Test static as a handler (section must NOT include vhost prefix) 
    4040        static = cherrypy.tools.staticdir.handler(section='/static', dir=curdir) 
    41      
    4241     
    4342    root = Root() 
    4443    root.mydom2 = VHost("Domain 2") 
    4544    root.mydom3 = VHost("Domain 3") 
    46     cherrypy.tree.mount(root, config={'/': { 
    47         'request.dispatch': _cpdispatch.VirtualHost( 
    48             **{'www.mydom2.com': '/mydom2', 
     45    hostmap = {'www.mydom2.com': '/mydom2', 
    4946               'www.mydom3.com': '/mydom3', 
    5047               'www.mydom4.com': '/dom4', 
    51                }), 
    52         }}) 
     48               } 
     49    cherrypy.tree.mount(root, config={ 
     50        '/': {'request.dispatch': cherrypy.dispatch.VirtualHost(**hostmap)}, 
     51        # Test static in config (section must include vhost prefix) 
     52        '/mydom2/static2': {'tools.staticdir.on': True, 
     53                            'tools.staticdir.root': curdir, 
     54                            'tools.staticdir.dir': 'static', 
     55                            'tools.staticdir.index': 'index.html', 
     56                            }, 
     57        }) 
    5358     
    5459    cherrypy.config.update({'environment': 'test_suite'}) 
     
    8792     
    8893    def test_VHost_plus_Static(self): 
     94        # Test static as a handler 
    8995        self.getPage("/static/style.css", [('Host', 'www.mydom2.com')]) 
    9096        self.assertStatus('200 OK') 
    9197        self.assertHeader('Content-Type', 'text/css') 
     98         
     99        # Test static in config 
     100        self.getPage("/static2/dirback.jpg", [('Host', 'www.mydom2.com')]) 
     101        self.assertStatus('200 OK') 
     102        self.assertHeader('Content-Type', 'image/jpeg') 
     103         
     104        # Test static config with "index" arg 
     105        self.getPage("/static2/", [('Host', 'www.mydom2.com')]) 
     106        self.assertStatus('200 OK') 
     107        self.assertBody('Hello, world\r\n') 
     108        self.getPage("/static2", [('Host', 'www.mydom2.com')]) 
     109        self.assertStatus('200 OK') 
     110        self.assertBody('Hello, world\r\n') 
    92111 
    93112 

Hosted by WebFaction

Log in as guest/cpguest to create tickets