comparison fileserver/web.py @ 12:8127dde8da22

fix slashing
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 29 Feb 2012 15:41:01 -0800
parents 8fb047af207a
children e3993fa05b89
comparison
equal deleted inserted replaced
11:1aaf2ba89b30 12:8127dde8da22
47 47
48 @staticmethod 48 @staticmethod
49 def normpath(path): 49 def normpath(path):
50 return os.path.normcase(os.path.abspath(path)) 50 return os.path.normcase(os.path.abspath(path))
51 51
52 def add_slash(self, request):
53 import pdb; pdb.set_trace()
54 location = ''
55 response = exc.HTTPMovedPermanantly()
56
52 def index(self, directory): 57 def index(self, directory):
53 """ 58 """
54 generate a directory listing for a given directory 59 generate a directory listing for a given directory
55 """ 60 """
56 parts = ['<html><head><title>Simple Index</title></head><body>'] 61 parts = ['<html><head><title>Simple Index</title></head><body>']
79 return exc.HTTPNotFound()(environ, start_response) 84 return exc.HTTPNotFound()(environ, start_response)
80 85
81 if os.path.isdir(full): 86 if os.path.isdir(full):
82 # serve directory index 87 # serve directory index
83 if not path_info.endswith('/'): 88 if not path_info.endswith('/'):
89 response = exc.HTTPMovedPermanently(add_slash=True)
90 return response(environ, start_response)
84 return self.add_slash(environ, start_response) 91 return self.add_slash(environ, start_response)
85 index = self.index(full) 92 index = self.index(full)
86 response_headers = [('Content-Type', 'text/html'), 93 response_headers = [('Content-Type', 'text/html'),
87 ('Content-Length', str(len(index)))] 94 ('Content-Length', str(len(index)))]
88 response = Response(index, content_type='text/html') 95 response = Response(index, content_type='text/html')