Skip to content

Commit

Permalink
Better headers for CGI enviroments
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.automattic.com/wordpress/trunk@2623 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
matt committed Jun 9, 2005
1 parent aa209f7 commit 09adfad
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 41 deletions.
5 changes: 1 addition & 4 deletions wp-admin/admin.php
Expand Up @@ -7,10 +7,7 @@
require_once(ABSPATH . 'wp-admin/admin-functions.php');
auth_redirect();

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');
nocache_headers();

update_category_cache();

Expand Down
28 changes: 7 additions & 21 deletions wp-blog-header.php
Expand Up @@ -107,14 +107,11 @@
}

// Sending HTTP headers
@header('X-Pingback: '. get_bloginfo('pingback_url'));

if ( !empty($error) && '404' == $error ) {
if ( preg_match('/cgi/', php_sapi_name()) )
@header('Status: 404 Not Found');
else
@header('HTTP/1.x 404 Not Found');
status_header( 404 );
} else if ( empty($feed) ) {
@header('X-Pingback: '. get_bloginfo('pingback_url'));
@header('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
Expand All @@ -125,7 +122,6 @@
$wp_etag = '"' . md5($wp_last_modified) . '"';
@header("Last-Modified: $wp_last_modified");
@header("ETag: $wp_etag");
@header('X-Pingback: ' . get_bloginfo('pingback_url'));

// Support for Conditional GET
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
Expand All @@ -141,17 +137,8 @@
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)) ) {
if ( preg_match('/cgi/',php_sapi_name()) ) {
header('Status: 304 Not Modified');
echo "\r\n\r\n";
exit;
} else {
if ( version_compare(phpversion(), '4.3.0', '>=') )
header('Not Modified', TRUE, 304);
else
header('HTTP/1.x 304 Not Modified');
exit;
}
status_header( 304 );
exit;
}
}

Expand Down Expand Up @@ -191,10 +178,9 @@
&& ( isset($rewrite) || (!empty($_SERVER['QUERY_STRING']) &&
(false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
$wp_query->is_404 = true;
if ( preg_match('/cgi/', php_sapi_name()) )
@header('Status: 404 Not Found');
else
@header('HTTP/1.x 404 Not Found');
status_header( 404 );
} else {
status_header( 200 );
}

if ($pagenow != 'post.php' && $pagenow != 'edit.php') {
Expand Down
5 changes: 1 addition & 4 deletions wp-comments-post.php
Expand Up @@ -52,10 +52,7 @@
setcookie('comment_author_email_' . COOKIEHASH, stripslashes($comment_author_email), time() + 30000000, COOKIEPATH);
setcookie('comment_author_url_' . COOKIEHASH, stripslashes($comment_author_url), time() + 30000000, COOKIEPATH);

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');
nocache_headers();

$location = (empty($_POST['redirect_to'])) ? $_SERVER["HTTP_REFERER"] : $_POST['redirect_to'];

Expand Down
32 changes: 32 additions & 0 deletions wp-includes/functions.php
Expand Up @@ -1849,4 +1849,36 @@ function wp_remote_fopen( $uri ) {
}
}

function status_header( $header ) {
if ( 200 == $header ) {
$text = 'OK';
} elseif ( 301 == $header ) {
$text = 'Moved Permanently';
} elseif ( 302 == $header ) {
$text = 'Moved Temporarily';
} elseif ( 304 == $header ) {
$text = 'Not Modified';
} elseif ( 404 == $header ) {
$text = 'Not Found';
} elseif ( 410 == $header ) {
$text = 'Gone';
}
if ( preg_match('/cgi/',php_sapi_name()) ) {
@header("Status: $header $text");
echo "\r\n\r\n";
} else {
if ( version_compare(phpversion(), '4.3.0', '>=') )
@header($text, TRUE, $header);
else
@header("HTTP/1.x $header $text");
}
}

function nocache_headers() {
@ 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');
}

?>
5 changes: 1 addition & 4 deletions wp-includes/pluggable-functions.php
Expand Up @@ -106,10 +106,7 @@ function auth_redirect() {
if ( (!empty($_COOKIE['wordpressuser_' . COOKIEHASH]) &&
!wp_login($_COOKIE['wordpressuser_' . COOKIEHASH], $_COOKIE['wordpresspass_' . COOKIEHASH], true)) ||
(empty($_COOKIE['wordpressuser_' . COOKIEHASH])) ) {
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');
nocache_headers();

header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
exit();
Expand Down
11 changes: 3 additions & 8 deletions wp-login.php
Expand Up @@ -4,10 +4,8 @@
$action = $_REQUEST['action'];
$error = '';

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');
header('Pragma: no-cache');
nocache_headers();

header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));

if ( defined('RELOCATE') ) { // Move flag is set
Expand All @@ -24,10 +22,7 @@

wp_clearcookie();
do_action('wp_logout');
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');
nocache_headers();
wp_redirect('wp-login.php');
exit();

Expand Down

0 comments on commit 09adfad

Please sign in to comment.