summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Koenig2009-01-10 01:03:17 (GMT)
committerJosh Koenig2009-01-10 01:03:17 (GMT)
commitd152f823a2b7cbbaf0a3e5a60e4e640402af0cee (patch)
tree81c163159099d9c49b11c4d5bd1246eda0002456
parenta54f965cdf3483e342b7cf7ac5dda1ce02e94262 (diff)
committing http://drupal.org/node/311988#comment-1162298
thanks to Alexander Ufimtsev and mcarbone for the review.
-rw-r--r--boost.module25
1 files changed, 19 insertions, 6 deletions
diff --git a/boost.module b/boost.module
index 8ebf7e3..b07a5a4 100644
--- a/boost.module
+++ b/boost.module
@@ -306,7 +306,7 @@ function _boost_ob_handler($buffer) {
chdir(dirname($_SERVER['SCRIPT_FILENAME']));
// Check the currently set content type; at present we can't deal with anything else than HTML.
- if (_boost_get_content_type() == 'text/html') {
+ if (_boost_get_content_type() == 'text/html' && _boost_get_http_status() == 200) {
if (strlen($buffer) > 0) { // Sanity check
boost_cache_set($GLOBALS['_boost_path'], $buffer);
}
@@ -324,14 +324,27 @@ function _boost_ob_handler($buffer) {
* has overridden the content type.
*/
function _boost_get_content_type($default = NULL) {
- static $regex = '/^Content-Type:\s*([\w\d\/\-]+)/i';
+ static $regex = '!^Content-Type:\s*([\w\d\/\-]+)!i';
+ return _boost_get_http_header($regex, $default);
+}
+
+/**
+ * Determines the HTTP response code that the current page request will be
+ * returning by examining the HTTP headers that have been output so far.
+ */
+function _boost_get_http_status($default = 200) {
+ static $regex = '!^HTTP/1.1\s+(\d+)!';
+ return (int)_boost_get_http_header($regex, $default);
+}
- // The last Content-Type header is the one that counts:
+function _boost_get_http_header($regex, $default = NULL) {
+ // The last header is the one that counts:
$headers = preg_grep($regex, explode("\n", drupal_set_header()));
- if (!empty($headers) && preg_match($regex, array_pop($headers), $matches))
+ if (!empty($headers) && preg_match($regex, array_pop($headers), $matches)) {
return $matches[1]; // found it
-
- return $default;
+ }
+ return $default; // no such luck
}
+
//////////////////////////////////////////////////////////////////////////////