def drupal_page_cache_header(cache): """ Set HTTP headers in preparation for a cached page response. The general approach here is that anonymous users can keep a local cache of the page, but must revalidate it on every request. Then, they are given a '304 Not Modified' response as long as they stay logged out and the page has not been modified. """ # Set default values: last_modified = php.gmdate("D, d M Y H:i:s", cache.created) + " GMT" etag = '"' + drupy_md5(last_modified) + '"' # See if the client has provided the required HTTP headers: if_modified_since = ( php.stripslashes(php.SERVER["HTTP_IF_MODIFIED_SINCE"]) if php.isset(php.SERVER, "HTTP_IF_MODIFIED_SINCE") else False ) if_none_match = ( php.stripslashes(php.SERVER["HTTP_IF_NONE_MATCH"]) if php.isset(php.SERVER, "HTTP_IF_NONE_MATCH") else False ) if ( if_modified_since and if_none_match and if_none_match == etag # etag must match and if_modified_since == last_modified ): # if-modified-since must match php.header(php.SERVER["SERVER_PROTOCOL"] + " 304 Not Modified") # All 304 responses must send an etag if the 200 response for the same # object contained an etag php.header("Etag: %(etag)s" % {"etag": etag}) exit() # Send appropriate response: php.header("Last-Modified: %(last_modified)s" % {"last_modified": last_modified}) php.header("Etag: %(etag)s" % {"etag": etag}) # The following headers force validation of cache: php.header("Expires: Sun, 19 Nov 1978 05:00:00 GMT") php.header("Cache-Control: must-revalidate") if variable_get("page_compression", True): # Determine if the browser accepts gzipped data. if php.strpos(php.SERVER["HTTP_ACCEPT_ENCODING"], "gzip") == False and php.function_exists("gzencode"): # Strip the gzip php.header and run uncompress. cache.data = php.gzinflate(php.substr(php.substr(cache.data, 10), 0, -8)) elif php.function_exists("gzencode"): php.header("Content-Encoding: gzip") # Send the original request's headers. We send them one after # another so PHP's php.header() def can deal with duplicate # headers. headers = php.explode("\n", cache.headers) for php.header_ in headers: php.header(php.header_) print cache.data
def drupal_page_header(): """ Set HTTP headers in preparation for a page response. Authenticated users are always given a 'no-cache' php.header, and will fetch a fresh page on every request. This prevents authenticated users seeing locally cached pages that show them as logged out. @see page_set_cache() """ php.header("Expires: Sun, 19 Nov 1978 05:00:00 GMT") php.header("Last-Modified: " + php.gmdate("%D, %d %M %Y %H:%i:%s") + " GMT") php.header("Cache-Control: store, no-cache, must-revalidate") php.header("Cache-Control: post-check=0, pre-check=0", False)
def drupal_page_cache_header(cache): """ Set HTTP headers in preparation for a cached page response. The general approach here is that anonymous users can keep a local cache of the page, but must revalidate it on every request. Then, they are given a '304 Not Modified' response as long as they stay logged out and the page has not been modified. """ # Set default values: last_modified = php.gmdate('D, d M Y H:i:s', cache.created) + ' GMT' etag = '"' + drupy_md5(last_modified) + '"' # See if the client has provided the required HTTP headers: if_modified_since = (php.stripslashes(php.SERVER['HTTP_IF_MODIFIED_SINCE']) \ if php.isset(php.SERVER, 'HTTP_IF_MODIFIED_SINCE') else False) if_none_match = (php.stripslashes(php.SERVER['HTTP_IF_NONE_MATCH']) \ if php.isset(php.SERVER, 'HTTP_IF_NONE_MATCH') else False) if (if_modified_since and if_none_match and if_none_match == etag # etag must match and if_modified_since == last_modified): # if-modified-since must match php.header(php.SERVER['SERVER_PROTOCOL'] + ' 304 Not Modified') # All 304 responses must send an etag if the 200 response for the same # object contained an etag php.header("Etag: %(etag)s" % {'etag': etag}) exit() # Send appropriate response: php.header("Last-Modified: %(last_modified)s" % \ {'last_modified':last_modified}) php.header("Etag: %(etag)s" % {'etag': etag}) # The following headers force validation of cache: php.header("Expires: Sun, 19 Nov 1978 05:00:00 GMT") php.header("Cache-Control: must-revalidate") if (variable_get('page_compression', True)): # Determine if the browser accepts gzipped data. if (php.strpos(php.SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') == False and \ php.function_exists('gzencode')): # Strip the gzip php.header and run uncompress. cache.data = php.gzinflate( php.substr(php.substr(cache.data, 10), 0, -8)) elif (php.function_exists('gzencode')): php.header('Content-Encoding: gzip') # Send the original request's headers. We send them one after # another so PHP's php.header() def can deal with duplicate # headers. headers = php.explode("\n", cache.headers) for php.header_ in headers: php.header(php.header_) print cache.data