From 1698e931891d7bc7f8eea6b6178ba81b60eb9baf Mon Sep 17 00:00:00 2001 From: emc3 Date: Tue, 26 Aug 2003 19:34:29 +0000 Subject: [PATCH] Added Etag support for Conditional GET, and fixed my horribly broken code from the last commit :) git-svn-id: http://svn.automattic.com/wordpress/trunk@348 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- b2rdf.php | 24 +++++++++++++++++------- b2rss.php | 22 ++++++++++++++++------ b2rss2.php | 24 ++++++++++++++++++------ 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/b2rdf.php b/b2rdf.php index 7e30cb471b..242d619220 100644 --- a/b2rdf.php +++ b/b2rdf.php @@ -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'; } ?> diff --git a/b2rss.php b/b2rss.php index 0b3311531f..f5ad8f197b 100644 --- a/b2rss.php +++ b/b2rss.php @@ -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; } diff --git a/b2rss2.php b/b2rss2.php index 55ff148c7b..fcd328c98a 100644 --- a/b2rss2.php +++ b/b2rss2.php @@ -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; }