Allow for the HTTP headers returned by WordPress to be filtered by a plugin. Fixes #9205 props filosofo.

git-svn-id: http://svn.automattic.com/wordpress/trunk@10619 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2009-02-21 21:39:06 +00:00
parent 5c4f21c4fe
commit 5930ffdfc4
2 changed files with 43 additions and 15 deletions

View File

@ -302,16 +302,17 @@ class WP {
* @since 2.0.0
*/
function send_headers() {
@header('X-Pingback: '. get_bloginfo('pingback_url'));
$headers = array('X-Pingback' => get_bloginfo('pingback_url'));
$status = null;
if ( is_user_logged_in() )
nocache_headers();
$headers = array_merge($headers, wp_get_nocache_headers());
if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) {
status_header( 404 );
$status = 404;
if ( !is_user_logged_in() )
nocache_headers();
@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
$headers = array_merge($headers, wp_get_nocache_headers());
$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
} else if ( empty($this->query_vars['feed']) ) {
@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
} else {
// We're showing a feed, so WP is indeed the only thing that last changed
if ( !empty($this->query_vars['withcomments'])
@ -329,8 +330,8 @@ class WP {
else
$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
$wp_etag = '"' . md5($wp_last_modified) . '"';
@header("Last-Modified: $wp_last_modified");
@header("ETag: $wp_etag");
$headers['Last-Modified'] = $wp_last_modified;
$headers['ETag'] = $wp_etag;
// Support for Conditional GET
if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
@ -347,11 +348,18 @@ class WP {
if ( ($client_last_modified && $client_etag) ?
(($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :
(($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
status_header( 304 );
exit;
$status = 304;
add_action('send_headers', 'exit', 1);
}
}
$headers = apply_filters('wp_headers', $headers, $this);
if ( ! empty( $status ) )
status_header( $status );
foreach( (array) $headers as $name => $field_value )
@header("{$name}: {$field_value}");
do_action_ref_array('send_headers', array(&$this));
}

View File

@ -1459,6 +1459,27 @@ function status_header( $header ) {
return @header( $status_header, true, $header );
}
/**
* Gets the header information to prevent caching.
*
* The several different headers cover the different ways cache prevention is handled
* by different browsers
*
* @since 2.8
*
* @uses apply_filters()
* @return array The associative array of header names and field values.
*/
function wp_get_nocache_headers() {
$headers = array(
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Last-Modified' => gmdate( 'D, d M Y H:i:s' ) . ' GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
'Pragma' => 'no-cache',
);
return apply_filters('nocache_headers', $headers);
}
/**
* Sets the headers to prevent caching for the different browsers.
*
@ -1466,13 +1487,12 @@ function status_header( $header ) {
* be sent so that all of them get the point that no caching should occur.
*
* @since 2.0.0
* @uses wp_get_nocache_headers()
*/
function nocache_headers() {
// why are these @-silenced when other header calls aren't?
@header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
@header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
@header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
@header( 'Pragma: no-cache' );
$headers = wp_get_nocache_headers();
foreach( (array) $headers as $name => $field_value )
@header("{$name}: {$field_value}");
}
/**