[z3-checkins] r50656 - in z3/deliverance/DeliveranceVHoster/trunk: . docs dvhoster

ianb at codespeak.net ianb at codespeak.net
Wed Jan 16 00:05:12 CET 2008


Author: ianb
Date: Wed Jan 16 00:05:10 2008
New Revision: 50656

Modified:
   z3/deliverance/DeliveranceVHoster/trunk/docs/configuration.txt
   z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py
   z3/deliverance/DeliveranceVHoster/trunk/fassembler_config.ini_tmpl
Log:
Added support for file: urls (from find_remote_uri, not remote_uri.txt).  Added some support for debugging routing

Modified: z3/deliverance/DeliveranceVHoster/trunk/docs/configuration.txt
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/docs/configuration.txt	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/docs/configuration.txt	Wed Jan 16 00:05:10 2008
@@ -42,6 +42,8 @@
 ``debug_bodies`` is also on then outgoing bodies will also be
 printed.  This is noisy, so should only be on for testing.
 
+``debug_routing`` shows routing information (how external URLs are mapped to
+internal resources).
 
 Hooks
 -----

Modified: z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/dvhoster/dispatcher.py	Wed Jan 16 00:05:10 2008
@@ -55,6 +55,7 @@
         self.app_conf = app_conf
         self.provider = DomainInfoSet(data_dir)
         self.rewrite_links = asbool(app_conf.get('rewrite_links', False))
+        self.debug_routing = asbool(app_conf.get('debug_routing', False))
 
         logger = make_logger(app_conf.get('logger'), 'dvhoster')
         self.logger = logger
@@ -129,6 +130,8 @@
         self.set_additional_headers(domain_info, environ)
 
         remote_uri = self.match_remote_uri(path_info, domain_info, environ)
+        if self.debug_routing:
+            print 'Routed path %s to %s' % (path_info, remote_uri)
         if not remote_uri:
             exc = httpexceptions.HTTPNotFound(
                 "No URL is mapped to %r (somewhat oddly); only %s prefixes "
@@ -148,7 +151,10 @@
             'script_name': environ['SCRIPT_NAME'],
             'path_info': environ['PATH_INFO'],
             }
+        old_remote_uri = remote_uri
         remote_uri = uritemplate.sub_vars(remote_uri, vars)
+        if self.debug_routing and remote_uri != old_remote_uri:
+            print 'Resolved URI %s to %s' % (old_remote_uri, remote_uri)
         
         environ['dvhoster.remote_uri'] = remote_uri
         if environ['SCRIPT_NAME']:
@@ -158,9 +164,15 @@
         if self.should_theme_uri:
             should_theme_uri = self.should_theme_uri(
                 remote_uri, environ, self.app_conf)
-        app = proxyapp.ForcedProxy(
-            remote=remote_uri,
-            force_host=True)
+            if self.debug_routing:
+                print 'Not theming %s' % remote_uri
+        if remote_uri.startswith('file:'):
+            filename = '/' + remote_uri[len('file:'):].lstrip('/')
+            app = StaticURLParser(filename)
+        else:
+            app = proxyapp.ForcedProxy(
+                remote=remote_uri,
+                force_host=True)
 
         if self.transcluder_enabled: 
             app = TranscluderMiddleware(app,
@@ -307,12 +319,20 @@
             if not path.endswith('/'):
                 path += '/'
             if path_info + '/' == path:
+                if self.debug_routing:
+                    print 'Path %s matches %r, but needs a trailing slash' % (path_info, path)
                 exc = httpexceptions.HTTPMovedPermanently(
                     headers=[('location', construct_url(environ, path_info=path_info+'/'))])
                 raise exc
             if path_info.startswith(path):
                 # Found a match
+                if self.debug_routing:
+                    print 'Found match for path %s against info %r' % (path_info, remote_uri_info)
                 remote_uri = remote_uri_info.get('remote_uri')
+                if remote_uri and remote_uri.lower().startswith('file:'):
+                    # This isn't allowed in remote_uri_info
+                    raise httpexceptions.HTTPForbidden("configured remote_uri values cannot be file: urls (%r)"
+                                                       % remote_uri)
                 environ['SCRIPT_NAME'] += path[:-1]
                 environ['PATH_INFO'] = path_info[len(path)-1:]
                 if remote_uri_info.get('headers'):
@@ -322,9 +342,15 @@
                             header_name = 'HTTP_' + header_name
                         environ[str(header_name)] = str(header_value)
                 if self.find_remote_uri:
+                    old_remote_uri = remote_uri
                     remote_uri = self.find_remote_uri(remote_uri, remote_uri_info, domain_info, environ, self.app_conf)
+                    if self.debug_routing and old_remote_uri != remote_uri:
+                        print 'find_remote_uri resolved path %s to %s' % (environ['PATH_INFO'], remote_uri)
                 return remote_uri
         if self.find_remote_uri:
             # Last change for find_remote_uri to do something
+            old_remote_uri = remote_uri
             remote_uri = self.find_remote_uri(remote_uri, None, domain_info, environ, self.app_conf)
+            if self.debug_routing and old_remote_uri != remote_uri:
+                print 'find_remote_uri resolved path %s to %s' % (environ['PATH_INFO'], remote_uri)
         return remote_uri

Modified: z3/deliverance/DeliveranceVHoster/trunk/fassembler_config.ini_tmpl
==============================================================================
--- z3/deliverance/DeliveranceVHoster/trunk/fassembler_config.ini_tmpl	(original)
+++ z3/deliverance/DeliveranceVHoster/trunk/fassembler_config.ini_tmpl	Wed Jan 16 00:05:10 2008
@@ -19,6 +19,8 @@
 #debug_headers = true
 # To view bodies:
 #debug_bodies = true
+# To show how routing is calculated:
+#debug_routing = true
 # To disable the rewriting of links:
 #rewrite_links = false
 # Use this to remove certain headers from any request:


More information about the z3-checkins mailing list