Author: jezdez
Date: 2010-09-26 15:46:37 -0500 (Sun, 26 Sep 2010)
New Revision: 13871

Modified:
   django/branches/releases/1.2.X/django/views/static.py
   django/branches/releases/1.2.X/tests/regressiontests/views/tests/static.py
Log:
Fixed #12544 and #13600 -- Fixed static files serving view to catch invalid 
date from If-Modified-Since header. Thanks akaihola and SmileyChris for patches.

Backport from trunk (r13870).

Modified: django/branches/releases/1.2.X/django/views/static.py
===================================================================
--- django/branches/releases/1.2.X/django/views/static.py       2010-09-26 
20:44:56 UTC (rev 13870)
+++ django/branches/releases/1.2.X/django/views/static.py       2010-09-26 
20:46:37 UTC (rev 13871)
@@ -135,6 +135,6 @@
             raise ValueError
         if mtime > header_mtime:
             raise ValueError
-    except (AttributeError, ValueError):
+    except (AttributeError, ValueError, OverflowError):
         return True
     return False

Modified: 
django/branches/releases/1.2.X/tests/regressiontests/views/tests/static.py
===================================================================
--- django/branches/releases/1.2.X/tests/regressiontests/views/tests/static.py  
2010-09-26 20:44:56 UTC (rev 13870)
+++ django/branches/releases/1.2.X/tests/regressiontests/views/tests/static.py  
2010-09-26 20:46:37 UTC (rev 13871)
@@ -2,6 +2,7 @@
 from os import path
 
 from django.test import TestCase
+from django.http import HttpResponseNotModified
 from regressiontests.views.urls import media_dir
 
 class StaticTests(TestCase):
@@ -27,3 +28,36 @@
         file = open(path.join(media_dir, file_name))
         self.assertEquals(file.read(), response.content)
 
+    def test_is_modified_since(self):
+        file_name = 'file.txt'
+        response = self.client.get(
+            '/views/site_media/%s' % file_name,
+            HTTP_IF_MODIFIED_SINCE='Thu, 1 Jan 1970 00:00:00 GMT')
+        file = open(path.join(media_dir, file_name))
+        self.assertEquals(file.read(), response.content)
+
+    def test_not_modified_since(self):
+        file_name = 'file.txt'
+        response = self.client.get(
+            '/views/site_media/%s' % file_name,
+            HTTP_IF_MODIFIED_SINCE='Mon, 18 Jan 2038 05:14:07 UTC'
+            # This is 24h before max Unix time. Remember to fix Django and
+            # update this test well before 2038 :)
+            )
+        self.assertTrue(isinstance(response, HttpResponseNotModified))
+
+    def test_invalid_if_modified_since(self):
+        """Handle bogus If-Modified-Since values gracefully
+
+        Assume that a file is modified since an invalid timestamp as per RFC
+        2616, section 14.25.
+        """
+        file_name = 'file.txt'
+        invalid_date = 'Mon, 28 May 999999999999 28:25:26 GMT'
+        response = self.client.get('/views/site_media/%s' % file_name,
+                                   HTTP_IF_MODIFIED_SINCE=invalid_date)
+        file = open(path.join(media_dir, file_name))
+        self.assertEquals(file.read(), response.content)
+        self.assertEquals(len(response.content),
+                          int(response['Content-Length']))
+

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to