Make WordPress Core

Changeset 1043


Ignore:
Timestamp:
03/31/2004 09:19:58 PM (21 years ago)
Author:
michelvaldrighi
Message:

restoring Dougal's Conditional GET logic, way better than the poop I had placed there

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-blog-header.php

    r1037 r1043  
    8686
    8787    // We're showing a feed, so WP is indeed the only thing that last changed
    88     $last_modified_date = mysql2date("D, d M Y H:i:s", get_lastpostmodified('GMT')).' GMT';
    89     @header('Last Modified: '.$last_modified_date);
    90     @header('ETag: "'.md5($last_modified_date).'"');
     88    $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT')).' GMT';
     89    $wp_etag = '"'.md5($wp_last_modified).'"';
     90    @header('Last Modified: '.$wp_last_modified);
     91    @header('ETag: '.$wp_etag);
    9192    @header ('X-Pingback: ' . get_settings('siteurl') . '/xmlrpc.php');
    9293
    93     // Checking If-Modified-Since and If-None-Match,
    94     // works only on Apache but should fail gracefully elsewhere
    95     $request_headers = getallheaders();
    96 
    97     if ( !empty($request_headers['If-Modified-Since']) OR !empty($request_headers['If-None-Match']) ) {
    98 
    99       $_match_ifmodifiedsince = 0;
    100       $_match_ifnonematch = 0;
    101 
    102       if (!empty($request_headers['If-Modified-Since'])) {
    103         if (strtotime($request_headers['If-Modified-Since']) >= strtotime($last_modified_date)) {
    104           $_match_ifmodifiedsince = 1;
    105         } else {
    106           $_match_ifmodifiedsince = -1;
    107         }
    108       }
    109       if (!empty($request_headers['If-None-Match'])) {
    110         if ($request_headers['If-None-Match'] == '"'.md5($last_modified_date).'"') {
    111           $_match_ifnonematch = 1;
    112         } else {
    113           $_match_ifnonematch = -1;
    114         }
    115       }
    116 
    117       // if one element is present but doesn't match the header, the -1 makes this <=0
    118       if ($_match_ifmodifiedsince + $_match_ifnonematch > 0) {
    119         header("HTTP/1.1 304 Not Modified\n\n");
    120       }
     94    // Support for Conditional GET
     95    $client_last_modified = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
     96    $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
     97
     98    if ( ($client_last_modified && $client_etag) ?
     99        (($client_last_modified == $wp_last_modified) && ($client_etag == $wp_etag)) :
     100        (($client_last_modified == $wp_last_modified) || ($client_etag == $wp_etag)) ) {
     101        header('HTTP/1.1 304 Not Modified');
     102        echo "\r\n\r\n";
     103        exit;
    121104    }
     105
    122106}
    123107
Note: See TracChangeset for help on using the changeset viewer.