function xmlsitemap_output_file in XML sitemap 6.2
Same name and namespace in other branches
- 8 xmlsitemap.module \xmlsitemap_output_file()
- 7.2 xmlsitemap.pages.inc \xmlsitemap_output_file()
Output the contents of a file to the browser and check caching headers.
1 call to xmlsitemap_output_file()
- xmlsitemap_output_chunk in ./
xmlsitemap.pages.inc - Output a sitemap page.
File
- ./
xmlsitemap.pages.inc, line 63 - Page callbacks for the xmlsitemap module.
Code
function xmlsitemap_output_file($file, array $headers = array()) {
if (!file_exists($file) || !is_readable($file)) {
return drupal_not_found();
}
$mtime = filemtime($file);
$last_modified = gmdate(DATE_RFC1123, $mtime);
$etag = '"' . md5($last_modified) . '"';
// See if the client has provided the required HTTP headers.
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;
if ($if_modified_since && $if_none_match && $if_none_match == $etag && $if_modified_since == $last_modified) {
header('HTTP/1.1 304 Not Modified');
// All 304 responses must send an etag if the 200 response for the same object contained an etag
header('Etag: ' . $etag);
exit;
}
$headers += array(
'Content-type: text/xml; charset=utf-8',
//'Content-length: ' . filesize($file),
'Last-modified: ' . $last_modified,
'Etag: ' . $etag,
'Expires: ' . gmdate(DATE_RFC1123, $mtime + variable_get('xmlsitemap_minimum_lifetime', 0)),
'Cache-Control: must-revalidate',
'X-Robots-Tag: noindex, follow',
);
// Transfer the file as output.
xmlsitemap_file_transfer($file, $headers);
}