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