From c1a4cb1d01dc19650219566b60671abc767af662 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 16 May 2010 18:24:26 -0400 Subject: [PATCH 1/4] [ticket/7782] Send status line using refactored download/file.php logic. PHPBB3-7782 --- phpBB/download/file.php | 10 +--------- phpBB/includes/functions.php | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 00b8e2e656..2154847865 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -670,15 +670,7 @@ function set_modified_headers($stamp, $browser) { if ($last_load !== false && $last_load >= $stamp) { - if (substr(strtolower(@php_sapi_name()),0,3) === 'cgi') - { - // in theory, we shouldn't need that due to php doing it. Reality offers a differing opinion, though - header('Status: 304 Not Modified', true, 304); - } - else - { - header('HTTP/1.0 304 Not Modified', true, 304); - } + send_status_line(304, 'Not Modified'); // seems that we need those too ... browsers header('Pragma: public'); header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 31536000)); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index cd8447a2a3..bc7c426e44 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2578,6 +2578,27 @@ function meta_refresh($time, $url, $disable_cd_check = false) return $url; } +function send_status_line($code, $message) +{ + if (substr(strtolower(@php_sapi_name()),0,3) === 'cgi') + { + // in theory, we shouldn't need that due to php doing it. Reality offers a differing opinion, though + header("Status: $code $message", true, $code); + } + else + { + if (isset($_SERVER['HTTP_VERSION'])) + { + $version = $_SERVER['HTTP_VERSION']; + } + else + { + $version = 'HTTP/1.0'; + } + header("$version $code $message", true, $code); + } +} + //Form validation @@ -3623,7 +3644,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) if ($msg_text == 'NO_FORUM' || $msg_text == 'NO_TOPIC' || $msg_text == 'NO_USER') { - header("HTTP/1.x 404 Not Found"); + send_status_line(404, 'Not Found'); } $msg_text = (!empty($user->lang[$msg_text])) ? $user->lang[$msg_text] : $msg_text; From 691f682fc2a69fed28bdca76f714d20be9277af6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 16 May 2010 19:52:01 -0400 Subject: [PATCH 2/4] [ticket/7782] Added phpdoc comment for send_status_line function. PHPBB3-7782 --- phpBB/includes/functions.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index bc7c426e44..178bb3ff3f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2578,6 +2578,26 @@ function meta_refresh($time, $url, $disable_cd_check = false) return $url; } +/** +* Outputs correct status line header. +* +* Depending on php sapi one of the two following forms is used: +* +* Status: 404 Not Found +* +* HTTP/1.x 404 Not Found +* +* HTTP version is taken from HTTP_VERSION environment variable, +* and defaults to 1.0. +* +* Sample usage: +* +* send_status_line(404, 'Not Found'); +* +* @param int $code HTTP status code +* @param string $message Message for the status code +* @return void +*/ function send_status_line($code, $message) { if (substr(strtolower(@php_sapi_name()),0,3) === 'cgi') From d721e94b888b657c8e36729db2c455812308cdc3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 17 May 2010 02:01:13 -0400 Subject: [PATCH 3/4] [ticket/7782] Added spaces. PHPBB3-7782 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 178bb3ff3f..862ab3b367 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2600,7 +2600,7 @@ function meta_refresh($time, $url, $disable_cd_check = false) */ function send_status_line($code, $message) { - if (substr(strtolower(@php_sapi_name()),0,3) === 'cgi') + if (substr(strtolower(@php_sapi_name()), 0, 3) === 'cgi') { // in theory, we shouldn't need that due to php doing it. Reality offers a differing opinion, though header("Status: $code $message", true, $code); From c185e45e09032e3ac32149a91f0133deb425acaa Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 17 May 2010 14:14:53 -0400 Subject: [PATCH 4/4] [ticket/7782] Return 404 HTTP status code for nonexistent attachments. PHPBB3-7782 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 862ab3b367..3e80f93114 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3662,7 +3662,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) $user->setup(); } - if ($msg_text == 'NO_FORUM' || $msg_text == 'NO_TOPIC' || $msg_text == 'NO_USER') + if ($msg_text == 'ERROR_NO_ATTACHMENT' || $msg_text == 'NO_FORUM' || $msg_text == 'NO_TOPIC' || $msg_text == 'NO_USER') { send_status_line(404, 'Not Found'); }