From 57c6617c92959856e8cacd809f0e29f57df4f318 Mon Sep 17 00:00:00 2001
From: Aymeric Augustin <aymeric.augustin@m4x.org>
Date: Thu, 24 Jan 2013 11:01:12 +0100
Subject: [PATCH] Minor optimization in the static serve view.

---
 django/views/static.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/django/views/static.py b/django/views/static.py
index f61ba28bd5..12af130796 100644
--- a/django/views/static.py
+++ b/django/views/static.py
@@ -58,12 +58,13 @@ def serve(request, path, document_root=None, show_indexes=False):
         raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})
     # Respect the If-Modified-Since header.
     statobj = os.stat(fullpath)
-    mimetype, encoding = mimetypes.guess_type(fullpath)
-    mimetype = mimetype or 'application/octet-stream'
     if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
                               statobj.st_mtime, statobj.st_size):
         return HttpResponseNotModified()
-    response = CompatibleStreamingHttpResponse(open(fullpath, 'rb'), content_type=mimetype)
+    content_type, encoding = mimetypes.guess_type(fullpath)
+    content_type = content_type or 'application/octet-stream'
+    response = CompatibleStreamingHttpResponse(open(fullpath, 'rb'),
+                                               content_type=content_type)
     response["Last-Modified"] = http_date(statobj.st_mtime)
     if stat.S_ISREG(statobj.st_mode):
         response["Content-Length"] = statobj.st_size