Author: adrian
Date: 2008-09-17 00:42:12 -0500 (Wed, 17 Sep 2008)
New Revision: 9055
Modified:
django/trunk/django/core/servers/basehttp.py
Log:
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
Modified: django/trunk/django/core/servers/basehttp.py
===================================================================
--- django/trunk/django/core/servers/basehttp.py 2008-09-17 05:18:41 UTC
(rev 9054)
+++ django/trunk/django/core/servers/basehttp.py 2008-09-17 05:42:12 UTC
(rev 9055)
@@ -11,6 +11,7 @@
import mimetypes
import os
import re
+import stat
import sys
import urllib
@@ -648,13 +649,23 @@
headers = {'Content-type': 'text/plain'}
output = ['Permission denied: %s' % file_path]
else:
- status = '200 OK'
- headers = {}
- mime_type = mimetypes.guess_type(file_path)[0]
- if mime_type:
- headers['Content-Type'] = mime_type
- output = [fp.read()]
- fp.close()
+ # This is a very simple implementation of conditional GET with
+ # the Last-Modified header. It makes media files a bit speedier
+ # because the files are only read off disk for the first
+ # request (assuming the browser/client supports conditional
+ # GET).
+ mtime = http_date(os.stat(file_path)[stat.ST_MTIME])
+ headers = {'Last-Modified': mtime}
+ if environ.get('HTTP_IF_MODIFIED_SINCE', None) == mtime:
+ status = '304 NOT MODIFIED'
+ output = []
+ else:
+ status = '200 OK'
+ mime_type = mimetypes.guess_type(file_path)[0]
+ if mime_type:
+ headers['Content-Type'] = mime_type
+ output = [fp.read()]
+ fp.close()
start_response(status, headers.items())
return output
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---