def make_conditional(self, req): """ Make the response conditional to the HTTP headers in the CGI/WSGI `environ`. Checks for ``If-none-match`` and ``If-modified-since`` headers and compares to the etag and timestamp of this response. If the content was not modified the repsonse will changed to HTTP 304 Not Modified. """ if req is None: return environ = req.environ not_modified = False if self.etag == environ.get('HTTP_IF_NONE_MATCH', -1): not_modified = True elif self._timestamp is not None: date = environ.get('HTTP_IF_MODIFIED_SINCE', None) timestamp = parse_httpdate(date) if timestamp is not None and self._timestamp <= timestamp: not_modified = True if not_modified: self.status = 304 self.response = [] if 'Content-type' in self.headers: del self.headers['Content-type']
def test_parse_httpdate(self): for date in ( "Fri, 13 Feb 2009 23:31:30 GMT", "Friday, 13-Feb-09 23:31:30 GMT", "Fri Feb 13 23:31:30 2009", ): assert parse_httpdate(date) == 1234567890
def test_parse_httpdate(self): for date in ( 'Fri, 13 Feb 2009 23:31:30 GMT', 'Friday, 13-Feb-09 23:31:30 GMT', 'Fri Feb 13 23:31:30 2009', ): eq_(parse_httpdate(date), 1234567890)
def test_parse_invalid(self): for date in ( None, 'foobar', '4823764923', 'Fri, 13 Foo 2009 23:31:30 GMT' ): eq_(parse_httpdate(date), None)
def test_parse_invalid(self): for date in (None, "foobar", "4823764923", "Fri, 13 Foo 2009 23:31:30 GMT"): assert parse_httpdate(date) == None
def test_parse_invalid(self): for date in (None, 'foobar', '4823764923', 'Fri, 13 Foo 2009 23:31:30 GMT'): eq_(parse_httpdate(date), None)