From c2de944401886d1474973ac3bb035f9e1fc22335 Mon Sep 17 00:00:00 2001
From: Bastian Kleineidam <calvin@debian.org>
Date: Fri, 25 Jan 2008 17:42:37 +0100
Subject: Split off file-serving capability
Split the file-serving capability of the Django static view into a
separate function, and add the ability to set the mimetype manually.
Signed-off-by: Bastian Kleineidam <calvin@debian.org>
diff --git a/django/views/static.py b/django/views/static.py
index 80c9bff..79b6192 100644
      
        
          
        
        
          
            | 
              a
             | 
            
              b
             | 
            
               def serve(request, path, document_root=None, show_indexes=False):
               
             | 
          
        
        
          
            | 63 | 63 |         if show_indexes: | 
          
          
            | 64 | 64 |             return directory_index(newpath, fullpath) | 
          
          
            | 65 | 65 |         raise Http404, "Directory indexes are not allowed here." | 
          
        
        
          
            |   | 66 |     return serve_file(request, fullpath) | 
          
          
            |   | 67 |  | 
          
          
            |   | 68 | def serve_file (request, fullpath, mimetype=None): | 
          
        
        
          
            | 66 | 69 |     if not os.path.exists(fullpath): | 
          
          
            | 67 | 70 |         raise Http404, '"%s" does not exist' % fullpath | 
          
          
            | 68 | 71 |     # Respect the If-Modified-Since header. | 
          
        
        
          
            | … | 
            … | 
            
               def serve(request, path, document_root=None, show_indexes=False):
               
             | 
          
        
        
          
            | 70 | 73 |     if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'), | 
          
          
            | 71 | 74 |                               statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]): | 
          
          
            | 72 | 75 |         return HttpResponseNotModified() | 
          
        
        
          
            | 73 |   |     mimetype = mimetypes.guess_type(fullpath)[0] or 'application/octet-stream' | 
          
          
            |   | 76 |     if mimetype is None: | 
          
          
            |   | 77 |         mimetype = mimetypes.guess_type(fullpath)[0] or 'application/octet-stream' | 
          
        
        
          
            | 74 | 78 |     f = open(fullpath, 'rb') | 
          
          
            | 75 | 79 |     try: | 
          
          
            | 76 | 80 |         contents = f.read() |