Make WordPress Core

Changeset 1036


Ignore:
Timestamp:
03/31/2004 03:54:58 AM (21 years ago)
Author:
michelvaldrighi
Message:

your aggregator will love you, feeds now support sending a 304 Not Modified header when needed

File:
1 edited

Legend:

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

    r1023 r1036  
    8484    @header ('X-Pingback: '. get_settings('siteurl') . '/xmlrpc.php');
    8585} else {
     86
    8687    // We're showing a feed, so WP is indeed the only thing that last changed
    87     @header('Last Modified: ' . mysql2date("D, d M Y H:i:s", get_lastpostmodified('GMT')).' GMT');
     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).'"');
    8891    @header ('X-Pingback: ' . get_settings('siteurl') . '/xmlrpc.php');
     92
     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) {
     119        header("HTTP/1.1 304 Not Modified\n\n");
     120      }
     121    }
    89122}
    90123
Note: See TracChangeset for help on using the changeset viewer.