Make WordPress Core

Changeset 10619


Ignore:
Timestamp:
02/21/2009 09:39:06 PM (16 years ago)
Author:
westi
Message:

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

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/classes.php

    r10573 r10619  
    303303     */
    304304    function send_headers() {
    305         @header('X-Pingback: '. get_bloginfo('pingback_url'));
     305        $headers = array('X-Pingback' => get_bloginfo('pingback_url'));
     306        $status = null;
    306307        if ( is_user_logged_in() )
    307             nocache_headers();
     308            $headers = array_merge($headers, wp_get_nocache_headers());
    308309        if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) {
    309             status_header( 404 );
     310            $status = 404;
    310311            if ( !is_user_logged_in() )
    311                 nocache_headers();
    312             @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     312                $headers = array_merge($headers, wp_get_nocache_headers());
     313            $headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
    313314        } else if ( empty($this->query_vars['feed']) ) {
    314             @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     315            $headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
    315316        } else {
    316317            // We're showing a feed, so WP is indeed the only thing that last changed
     
    330331                $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
    331332            $wp_etag = '"' . md5($wp_last_modified) . '"';
    332             @header("Last-Modified: $wp_last_modified");
    333             @header("ETag: $wp_etag");
     333            $headers['Last-Modified'] = $wp_last_modified;
     334            $headers['ETag'] = $wp_etag;
    334335
    335336            // Support for Conditional GET
     
    348349                     (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :
    349350                     (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
    350                 status_header( 304 );
    351                 exit;
     351                $status = 304;
     352                add_action('send_headers', 'exit', 1);
    352353            }
    353354        }
     355
     356        $headers = apply_filters('wp_headers', $headers, $this);
     357
     358        if ( ! empty( $status ) )
     359            status_header( $status );
     360        foreach( (array) $headers as $name => $field_value )
     361            @header("{$name}: {$field_value}");
    354362
    355363        do_action_ref_array('send_headers', array(&$this));
  • trunk/wp-includes/functions.php

    r10617 r10619  
    14611461
    14621462/**
     1463 * Gets the header information to prevent caching.
     1464 *
     1465 * The several different headers cover the different ways cache prevention is handled
     1466 * by different browsers
     1467 *
     1468 * @since 2.8
     1469 *
     1470 * @uses apply_filters()
     1471 * @return array The associative array of header names and field values.
     1472 */
     1473function wp_get_nocache_headers() {
     1474    $headers = array(
     1475        'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
     1476        'Last-Modified' => gmdate( 'D, d M Y H:i:s' ) . ' GMT',
     1477        'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
     1478        'Pragma' => 'no-cache',
     1479    );
     1480    return apply_filters('nocache_headers', $headers); 
     1481}
     1482
     1483/**
    14631484 * Sets the headers to prevent caching for the different browsers.
    14641485 *
     
    14671488 *
    14681489 * @since 2.0.0
     1490 * @uses wp_get_nocache_headers()
    14691491 */
    14701492function nocache_headers() {
    1471     // why are these @-silenced when other header calls aren't?
    1472     @header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
    1473     @header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
    1474     @header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
    1475     @header( 'Pragma: no-cache' );
     1493    $headers = wp_get_nocache_headers();
     1494    foreach( (array) $headers as $name => $field_value )
     1495        @header("{$name}: {$field_value}");     
    14761496}
    14771497
Note: See TracChangeset for help on using the changeset viewer.