etwist/request.py
changeset 5868 c4380d8cfc25
parent 5443 f299ee54d7e0
parent 5867 7ef636d24ab2
child 7879 9aae456abab5
equal deleted inserted replaced
5863:4495b9bc49df 5868:c4380d8cfc25
    80         """
    80         """
    81         if self.get_header('Cache-Control') in ('max-age=0', 'no-cache'):
    81         if self.get_header('Cache-Control') in ('max-age=0', 'no-cache'):
    82             # Expires header seems to be required by IE7
    82             # Expires header seems to be required by IE7
    83             self.add_header('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT')
    83             self.add_header('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT')
    84             return
    84             return
    85 
       
    86         # when using both 'Last-Modified' and 'ETag' response headers
    85         # when using both 'Last-Modified' and 'ETag' response headers
    87         # (i.e. using respectively If-Modified-Since and If-None-Match request
    86         # (i.e. using respectively If-Modified-Since and If-None-Match request
    88         # headers, see
    87         # headers, see
    89         # http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.4 for
    88         # http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.3.4 for
    90         # reference
    89         # reference
    91 
       
    92         cached_because_not_modified_since = False
       
    93 
       
    94         last_modified = self.headers_out.getHeader('last-modified')
    90         last_modified = self.headers_out.getHeader('last-modified')
    95         if last_modified is not None:
    91         if last_modified is not None:
    96             cached_because_not_modified_since = (self._twreq.setLastModified(last_modified)
    92             status = self._twreq.setLastModified(last_modified)
    97                                                  == http.CACHED)
    93             if status != http.CACHED:
    98 
    94                 return
    99         if not cached_because_not_modified_since:
       
   100             return
       
   101 
       
   102         cached_because_etag_is_same = False
       
   103         etag = self.headers_out.getRawHeaders('etag')
    95         etag = self.headers_out.getRawHeaders('etag')
   104         if etag is not None:
    96         if etag is not None:
   105             cached_because_etag_is_same = self._twreq.setETag(etag[0]) == http.CACHED
    97             status = self._twreq.setETag(etag[0])
   106 
    98             if status == http.CACHED:
   107         if cached_because_etag_is_same:
    99                 response = not_modified_response(self._twreq, self._headers_in)
   108             response = not_modified_response(self._twreq, self._headers_in)
   100                 raise DirectResponse(response)
   109             raise DirectResponse(response)
       
   110 
       
   111         # Expires header seems to be required by IE7
   101         # Expires header seems to be required by IE7
   112         self.add_header('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT')
   102         self.add_header('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT')
   113 
   103 
   114     def header_accept_language(self):
   104     def header_accept_language(self):
   115         """returns an ordered list of preferred languages"""
   105         """returns an ordered list of preferred languages"""