Django

Code

Show
Ignore:
Timestamp:
09/17/08 00:42:12 (4 months ago)
Author:
adrian
Message:

Fixed #8409 -- The runserver now uses conditional GET for admin media files, instead of reloading the files off disk for every request. Thanks for reporting, andylowry

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/servers/basehttp.py

    r7801 r9055  
    1212import os 
    1313import re 
     14import stat 
    1415import sys 
    1516import urllib 
     
    649650                output = ['Permission denied: %s' % file_path] 
    650651            else: 
    651                 status = '200 OK' 
    652                 headers = {} 
    653                 mime_type = mimetypes.guess_type(file_path)[0] 
    654                 if mime_type: 
    655                     headers['Content-Type'] = mime_type 
    656                 output = [fp.read()] 
    657                 fp.close() 
     652                # This is a very simple implementation of conditional GET with 
     653                # the Last-Modified header. It makes media files a bit speedier 
     654                # because the files are only read off disk for the first 
     655                # request (assuming the browser/client supports conditional 
     656                # GET). 
     657                mtime = http_date(os.stat(file_path)[stat.ST_MTIME]) 
     658                headers = {'Last-Modified': mtime} 
     659                if environ.get('HTTP_IF_MODIFIED_SINCE', None) == mtime: 
     660                    status = '304 NOT MODIFIED' 
     661                    output = [] 
     662                else: 
     663                    status = '200 OK' 
     664                    mime_type = mimetypes.guess_type(file_path)[0] 
     665                    if mime_type: 
     666                        headers['Content-Type'] = mime_type 
     667                    output = [fp.read()] 
     668                    fp.close() 
    658669        start_response(status, headers.items()) 
    659670        return output