changeset 12:8127dde8da22

fix slashing
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 29 Feb 2012 15:41:01 -0800
parents 1aaf2ba89b30
children e3993fa05b89
files fileserver/web.py tests/doctest.txt
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/fileserver/web.py	Wed Feb 29 15:22:51 2012 -0800
+++ b/fileserver/web.py	Wed Feb 29 15:41:01 2012 -0800
@@ -49,6 +49,11 @@
     def normpath(path):
         return os.path.normcase(os.path.abspath(path))
 
+    def add_slash(self, request):
+        import pdb; pdb.set_trace()
+        location = ''
+        response = exc.HTTPMovedPermanantly()
+
     def index(self, directory):
         """
         generate a directory listing for a given directory
@@ -81,6 +86,8 @@
         if os.path.isdir(full):
             # serve directory index
             if not path_info.endswith('/'):
+                response = exc.HTTPMovedPermanently(add_slash=True)
+                return response(environ, start_response)
                 return self.add_slash(environ, start_response)
             index = self.index(full)
             response_headers = [('Content-Type', 'text/html'),
--- a/tests/doctest.txt	Wed Feb 29 15:22:51 2012 -0800
+++ b/tests/doctest.txt	Wed Feb 29 15:41:01 2012 -0800
@@ -5,6 +5,7 @@
 
     >>> import fileserver
     >>> import os
+    >>> import urlparse
     >>> from paste.fixture import TestApp
 
 Make a single file server::
@@ -53,7 +54,17 @@
 Ensure you can get resources from subdirectories::
 
     >>> response = testapp.get('/foo')
+    >>> response.status # 301 Moved Permanently
+    301
+    >>> location = response.header_dict['location']
+    >>> shema, netloc, path, query, fragment = urlparse.urlsplit(location)
+    >>> path
+    '/foo/'
+    >>> response = testapp.get('/foo/')
     >>> response.status
+    200
+    >>> 'bar.txt' in response.body
+    True
 
 Ensure you can't get to non-allowed resources::