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
This commit is contained in:
parent
f8530b137b
commit
1698e93189
24
b2rdf.php
24
b2rdf.php
|
@ -3,30 +3,40 @@ $blog = 1; // enter your blog's ID
|
||||||
$doing_rss=1;
|
$doing_rss=1;
|
||||||
header('Content-type: text/xml');
|
header('Content-type: text/xml');
|
||||||
|
|
||||||
|
include('blog.header.php');
|
||||||
|
|
||||||
// Handle Conditional GET
|
// Handle Conditional GET
|
||||||
|
|
||||||
// Get the time of the most recent article
|
// Get the time of the most recent article
|
||||||
$sql = "SELECT max(post_date) FROM $tableposts";
|
$sql = "SELECT max(post_date) FROM $tableposts";
|
||||||
|
|
||||||
$maxdate = $wbdp->get_var($sql);
|
$maxdate = $wpdb->get_var($sql);
|
||||||
|
|
||||||
$unixtime = strtotime($maxdate);
|
$unixtime = strtotime($maxdate);
|
||||||
|
|
||||||
// format timestamp for Last-Modified header
|
// 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
|
// 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 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");
|
header("HTTP/1.1 304 Not Modified");
|
||||||
|
echo "\r\n\r\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
include('blog.header.php');
|
|
||||||
add_filter('the_content', 'trim');
|
add_filter('the_content', 'trim');
|
||||||
if (!isset($rss_language)) { $rss_language = 'en'; }
|
if (!isset($rss_language)) { $rss_language = 'en'; }
|
||||||
?>
|
?>
|
||||||
|
|
22
b2rss.php
22
b2rss.php
|
@ -3,31 +3,41 @@
|
||||||
$blog = 1; // enter your blog's ID
|
$blog = 1; // enter your blog's ID
|
||||||
$doing_rss=1;
|
$doing_rss=1;
|
||||||
header('Content-type: text/xml');
|
header('Content-type: text/xml');
|
||||||
|
include('blog.header.php');
|
||||||
|
|
||||||
// Handle Conditional GET
|
// Handle Conditional GET
|
||||||
|
|
||||||
// Get the time of the most recent article
|
// Get the time of the most recent article
|
||||||
$sql = "SELECT max(post_date) FROM $tableposts";
|
$sql = "SELECT max(post_date) FROM $tableposts";
|
||||||
|
|
||||||
$maxdate = $wbdp->get_var($sql);
|
$maxdate = $wpdb->get_var($sql);
|
||||||
|
|
||||||
$unixtime = strtotime($maxdate);
|
$unixtime = strtotime($maxdate);
|
||||||
|
|
||||||
// format timestamp for Last-Modified header
|
// 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
|
// 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 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");
|
header("HTTP/1.1 304 Not Modified");
|
||||||
|
echo "\r\n\r\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
include('blog.header.php');
|
|
||||||
if (!isset($rss_language)) { $rss_language = 'en'; }
|
if (!isset($rss_language)) { $rss_language = 'en'; }
|
||||||
if (!isset($rss_encoded_html)) { $rss_encoded_html = 0; }
|
if (!isset($rss_encoded_html)) { $rss_encoded_html = 0; }
|
||||||
if (!isset($rss_excerpt_length) || ($rss_encoded_html == 1)) { $rss_excerpt_length = 0; }
|
if (!isset($rss_excerpt_length) || ($rss_encoded_html == 1)) { $rss_excerpt_length = 0; }
|
||||||
|
|
24
b2rss2.php
24
b2rss2.php
|
@ -4,29 +4,41 @@ $blog=1; // enter your blog's ID
|
||||||
$doing_rss=1;
|
$doing_rss=1;
|
||||||
header('Content-type: text/xml');
|
header('Content-type: text/xml');
|
||||||
|
|
||||||
|
include('blog.header.php');
|
||||||
|
|
||||||
// Handle Conditional GET
|
// Handle Conditional GET
|
||||||
|
|
||||||
// Get the time of the most recent article
|
// Get the time of the most recent article
|
||||||
$sql = "SELECT max(post_date) FROM $tableposts";
|
$sql = "SELECT max(post_date) FROM $tableposts";
|
||||||
|
|
||||||
$maxdate = $wbdp->get_var($sql);
|
$maxdate = $wpdb->get_var($sql);
|
||||||
|
|
||||||
$unixtime = strtotime($maxdate);
|
$unixtime = strtotime($maxdate);
|
||||||
|
|
||||||
// format timestamp for Last-Modified header
|
// 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
|
// 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 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");
|
header("HTTP/1.1 304 Not Modified");
|
||||||
|
echo "\r\n\r\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
include('blog.header.php');
|
|
||||||
if (!isset($rss_language)) { $rss_language = 'en'; }
|
if (!isset($rss_language)) { $rss_language = 'en'; }
|
||||||
if (!isset($rss_encoded_html)) { $rss_encoded_html = 0; }
|
if (!isset($rss_encoded_html)) { $rss_encoded_html = 0; }
|
||||||
if (!isset($rss_excerpt_length) || ($rss_encoded_html == 1)) { $rss_excerpt_length = 0; }
|
if (!isset($rss_excerpt_length) || ($rss_encoded_html == 1)) { $rss_excerpt_length = 0; }
|
||||||
|
|
Loading…
Reference in New Issue