Added Etag support for Conditional GET, and fixed my horribly broken code from the last commit :)

git-svn-id: https://develop.svn.wordpress.org/trunk@348 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dougal Campbell 2003-08-26 19:34:29 +00:00
parent 9a5e444594
commit 831051ff5f
3 changed files with 51 additions and 19 deletions

View File

@ -3,30 +3,40 @@ $blog = 1; // enter your blog's ID
$doing_rss=1;
header('Content-type: text/xml');
include('blog.header.php');
// Handle Conditional GET
// Get the time of the most recent article
$sql = "SELECT max(post_date) FROM $tableposts";
$maxdate = $wbdp->get_var($sql);
$maxdate = $wpdb->get_var($sql);
$unixtime = strtotime($maxdate);
// format timestamp for Last-Modified header
$last = gmdate("D, d M Y H:i:s \G\M\T",$unixtime);
$clast = gmdate("D, d M Y H:i:s \G\M\T",$unixtime);
$cetag = md5($last);
$slast = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$setag = $_SERVER['HTTP_IF_NONE_MATCH'];
// send it in a Last-Modified header
header("Last-Modified: $last");
header("Last-Modified: " . $clast);
header("Etag: " . $cetag);
// compare it to aggregator's If_Modified_Since
// compare it to aggregator's If-Modified-Since and If-None-Match headers
// if they match, send a 304 and die
if ($_SERVER[HTTP_IF_MODIFIED_SINCE] == $last){
// This logic says that if only one header is provided, just use that one,
// but if both headers exist, they *both* must match up with the locally
// generated values.
if (($slast?($slast == $clast):true) && ($setag?($setag == $cetag):true)){
header("HTTP/1.1 304 Not Modified");
echo "\r\n\r\n";
exit;
}
include('blog.header.php');
add_filter('the_content', 'trim');
if (!isset($rss_language)) { $rss_language = 'en'; }
?>

View File

@ -3,31 +3,41 @@
$blog = 1; // enter your blog's ID
$doing_rss=1;
header('Content-type: text/xml');
include('blog.header.php');
// Handle Conditional GET
// Get the time of the most recent article
$sql = "SELECT max(post_date) FROM $tableposts";
$maxdate = $wbdp->get_var($sql);
$maxdate = $wpdb->get_var($sql);
$unixtime = strtotime($maxdate);
// format timestamp for Last-Modified header
$last = gmdate("D, d M Y H:i:s \G\M\T",$unixtime);
$clast = gmdate("D, d M Y H:i:s \G\M\T",$unixtime);
$cetag = md5($last);
$slast = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$setag = $_SERVER['HTTP_IF_NONE_MATCH'];
// send it in a Last-Modified header
header("Last-Modified: $last");
header("Last-Modified: " . $clast);
header("Etag: " . $cetag);
// compare it to aggregator's If_Modified_Since
// compare it to aggregator's If-Modified-Since and If-None-Match headers
// if they match, send a 304 and die
if ($_SERVER[HTTP_IF_MODIFIED_SINCE] == $last){
// This logic says that if only one header is provided, just use that one,
// but if both headers exist, they *both* must match up with the locally
// generated values.
if (($slast?($slast == $clast):true) && ($setag?($setag == $cetag):true)){
header("HTTP/1.1 304 Not Modified");
echo "\r\n\r\n";
exit;
}
include('blog.header.php');
if (!isset($rss_language)) { $rss_language = 'en'; }
if (!isset($rss_encoded_html)) { $rss_encoded_html = 0; }
if (!isset($rss_excerpt_length) || ($rss_encoded_html == 1)) { $rss_excerpt_length = 0; }

View File

@ -4,29 +4,41 @@ $blog=1; // enter your blog's ID
$doing_rss=1;
header('Content-type: text/xml');
include('blog.header.php');
// Handle Conditional GET
// Get the time of the most recent article
$sql = "SELECT max(post_date) FROM $tableposts";
$maxdate = $wbdp->get_var($sql);
$maxdate = $wpdb->get_var($sql);
$unixtime = strtotime($maxdate);
// format timestamp for Last-Modified header
$last = gmdate("D, d M Y H:i:s \G\M\T",$unixtime);
$clast = gmdate("D, d M Y H:i:s \G\M\T",$unixtime);
$cetag = md5($last);
$slast = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$setag = $_SERVER['HTTP_IF_NONE_MATCH'];
// send it in a Last-Modified header
header("Last-Modified: $last");
header("Last-Modified: " . $clast);
header("Etag: " . $cetag);
// compare it to aggregator's If_Modified_Since
// compare it to aggregator's If-Modified-Since and If-None-Match headers
// if they match, send a 304 and die
if ($_SERVER[HTTP_IF_MODIFIED_SINCE] == $last){
// This logic says that if only one header is provided, just use that one,
// but if both headers exist, they *both* must match up with the locally
// generated values.
if (($slast?($slast == $clast):true) && ($setag?($setag == $cetag):true)){
header("HTTP/1.1 304 Not Modified");
echo "\r\n\r\n";
exit;
}
include('blog.header.php');
if (!isset($rss_language)) { $rss_language = 'en'; }
if (!isset($rss_encoded_html)) { $rss_encoded_html = 0; }
if (!isset($rss_excerpt_length) || ($rss_encoded_html == 1)) { $rss_excerpt_length = 0; }