r46963 - Apply ticket-3807-0.patch.

adiroiban-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Wed, 9 Mar 2016 03:38:25 -0700 (MST)
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: adiroiban
Date: Wed Mar  9 03:38:21 2016
New Revision: 46963

Added:
   branches/web-http-setLastModified-cache-3807/twisted/web/topfiles/3807.bugfix
Modified:
   branches/web-http-setLastModified-cache-3807/twisted/web/http.py
   branches/web-http-setLastModified-cache-3807/twisted/web/test/test_http.py

Log:
Apply ticket-3807-0.patch.

Modified: branches/web-http-setLastModified-cache-3807/twisted/web/http.py
==============================================================================
--- branches/web-http-setLastModified-cache-3807/twisted/web/http.py	(original)
+++ branches/web-http-setLastModified-cache-3807/twisted/web/http.py	Wed Mar  9 03:38:21 2016
@@ -1091,7 +1091,7 @@
                 modifiedSince = stringToDatetime(firstPart)
             except ValueError:
                 return None
-            if modifiedSince >= when:
+            if modifiedSince >= self.lastModified:
                 self.setResponseCode(NOT_MODIFIED)
                 return CACHED
         return None

Modified: branches/web-http-setLastModified-cache-3807/twisted/web/test/test_http.py
==============================================================================
--- branches/web-http-setLastModified-cache-3807/twisted/web/test/test_http.py	(original)
+++ branches/web-http-setLastModified-cache-3807/twisted/web/test/test_http.py	Wed Mar  9 03:38:21 2016
@@ -1469,6 +1469,89 @@
             "Python 3 has no separate long integer type.")
 
 
+    def test_setLastModified(self):
+        """
+        L{http.Request.setLastModified} takes a timestamp in seconds since the
+        epoch and sets the Last-Modified header for the response.
+        """
+        req = http.Request(DummyChannel(), False)
+        req.setLastModified(0)
+        self.assertEqual(req.lastModified, 0)
+
+
+    def test_setLastModifiedUpdate(self):
+        """
+        L{http.Request.setLastModified} takes a timestamp in seconds since the
+        epoch and sets the Last-Modified header for the response, if the
+        current value is lower (older) than the supplied value.
+        """
+        req = http.Request(DummyChannel(), False)
+        req.setLastModified(0)
+        req.setLastModified(1)
+        self.assertEqual(req.lastModified, 1)
+
+
+    def test_setLastModifiedIgnore(self):
+        """
+        L{http.Request.setLastModified} takes a timestamp in seconds since the
+        epoch and sets the Last-Modified header for the response, unless the
+        current value is lower (older) than the supplied value.
+        """
+        req = http.Request(DummyChannel(), False)
+        req.setLastModified(1)
+        req.setLastModified(0)
+        self.assertEqual(req.lastModified, 1)
+
+
+    def test_setLastModifiedCached(self):
+        """
+        L{http.Request.setLastModified} takes a timestamp in seconds since the
+        epoch and calls setLastModified for the response. If the resource has
+        not been modified since the 'if-modified-since' value of
+        one-day-after-the-epoch, then setLastModified should return CACHED
+        """
+        req = http.Request(DummyChannel(), False)
+        req.requestHeaders.setRawHeaders(
+            networkString('if-modified-since'),
+                          [b'02 Jan 1970 00:00:00 GMT']
+            )
+        result = req.setLastModified(0)
+        self.assertEqual(result,  http.CACHED)
+
+
+    def test_setLastModifiedNotCached(self):
+        """
+        L{http.Request.setLastModified} takes a timestamp in seconds since the
+        epoch and calls setLastModified for the response. If the resource has
+        been modified since the 'if-modified-since' value of 'the epoch', then
+        setLastModified should not return CACHED
+        """
+        req = http.Request(DummyChannel(), False)
+        req.requestHeaders.setRawHeaders(
+            networkString('if-modified-since'),
+                          [b'01 Jan 1970 00:00:00 GMT']
+            )
+        result = req.setLastModified(1000000)
+        self.assertEqual(result,  None)
+
+
+    def test_setLastModified3807(self):
+        """
+        L{http.Request.setLastModified} takes a timestamp in seconds since the
+        epoch and calls setLastModified for the response. If the resource has
+        been modified since the 'if-modified-since' value of 'the epoch', then
+        setLastModified should return None. Otherwise, CACHED. See ticket 3807
+        """
+        req = http.Request(DummyChannel(), False)
+        req.requestHeaders.setRawHeaders(
+            networkString('if-modified-since'),
+                          [b'01 Jan 1970 00:00:01 GMT']
+            )
+        result = req.setLastModified(1000000)
+        result = req.setLastModified(0)
+        self.assertEqual(result,  None)
+
+
     def test_setHost(self):
         """
         L{http.Request.setHost} sets the value of the host request header.