Index: bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.194
diff -u -p -r1.194 bootstrap.inc
--- bootstrap.inc	5 Oct 2007 14:50:25 -0000	1.194
+++ bootstrap.inc	8 Oct 2007 09:16:56 -0000
@@ -557,6 +557,35 @@ function drupal_load($type, $name) {
 }
 
 /**
+ * Set the given HTTP status with respect to the current PHP server API. 
+ * 
+ * As the CGI specification does not allow directly setting the HTTP status code,
+ * if the PHP Server API is CGI the HTTP/1.1 header will not work, using Status instead
+ * see http://www.php.net/manual/en/function.header.php#66254
+ *
+ * @param int $status
+ *   The http status.
+ * @param string $message
+ *   The header message.
+ */
+function drupal_http_status($status, $message = '') {
+  static $cgi;
+  if (!isset($cgi)) {
+    $cgi = substr(php_sapi_name(), 0, 3) === 'cgi';
+  }
+  
+  $http_status = $cgi ? 'Status: '. $status : 'HTTP/1.1 '. $status .' '. $message;
+  
+  // if common.inc has not been included yet, use the native header function 
+  if (function_exists('drupal_set_header')) {
+    drupal_set_header($http_status);
+  }
+  else {
+    header($http_status);
+  }
+}
+
+/**
  * Set HTTP headers in preparation for a page response.
  *
  * Authenticated users are always given a 'no-cache' header, and will
@@ -593,7 +622,7 @@ function drupal_page_cache_header($cache
   if ($if_modified_since && $if_none_match
       && $if_none_match == $etag // etag must match
       && $if_modified_since == $last_modified) {  // if-modified-since must match
-    header('HTTP/1.1 304 Not Modified');
+    drupal_http_status(304, 'Not Modified');
     // All 304 responses must send an etag if the 200 response for the same object contained an etag
     header("Etag: $etag");
     exit();
@@ -898,7 +927,7 @@ function _drupal_bootstrap($phase) {
     case DRUPAL_BOOTSTRAP_ACCESS:
       // Deny access to hosts which were banned - t() is not yet available.
       if (drupal_is_denied('host', ip_address())) {
-        header('HTTP/1.1 403 Forbidden');
+        drupal_http_status(403, 'Forbidden');
         print 'Sorry, '. check_plain(ip_address()) .' has been banned.';
         exit();
       }
Index: common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.697
diff -u -p -r1.697 common.inc
--- common.inc	6 Oct 2007 15:30:41 -0000	1.697
+++ common.inc	8 Oct 2007 09:25:39 -0000
@@ -312,7 +312,8 @@ function drupal_goto($path = '', $query 
   // need all session data written to the database before the redirect.
   session_write_close();
 
-  header('Location: '. $url, TRUE, $http_response_code);
+  drupal_http_status($http_response_code);
+  header('Location: '. $url, TRUE);
 
   // The "Location" header sends a redirect status code to the HTTP daemon. In
   // some cases this can go wrong, so we make sure none of the code below the
@@ -325,7 +326,7 @@ function drupal_goto($path = '', $query 
  */
 function drupal_site_offline() {
   drupal_maintenance_theme();
-  drupal_set_header('HTTP/1.1 503 Service unavailable');
+  drupal_http_status(503, 'Service unavailable');
   drupal_set_title(t('Site off-line'));
   print theme('maintenance_page', filter_xss_admin(variable_get('site_offline_message',
     t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal'))))));
@@ -335,8 +336,8 @@ function drupal_site_offline() {
  * Generates a 404 error if the request can not be handled.
  */
 function drupal_not_found() {
-  drupal_set_header('HTTP/1.1 404 Not Found');
-
+  drupal_http_status(404, 'Not Found');
+  
   watchdog('page not found', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
 
   // Keep old path for reference
@@ -364,7 +365,7 @@ function drupal_not_found() {
  * Generates a 403 error if the request is not allowed.
  */
 function drupal_access_denied() {
-  drupal_set_header('HTTP/1.1 403 Forbidden');
+  drupal_http_status(403, 'Forbidden');
   watchdog('access denied', check_plain($_GET['q']), NULL, WATCHDOG_WARNING);
 
 // Keep old path for reference
Index: database.mysql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.mysql.inc,v
retrieving revision 1.79
diff -u -p -r1.79 database.mysql.inc
--- database.mysql.inc	29 Aug 2007 18:38:55 -0000	1.79
+++ database.mysql.inc	17 Sep 2007 08:36:55 -0000
@@ -87,7 +87,7 @@ function db_connect($url) {
   if (!$connection) {
     // Show error screen otherwise
     drupal_maintenance_theme();
-    drupal_set_header('HTTP/1.1 503 Service Unavailable');
+    drupal_http_status(503, 'Service Unavailable');
     drupal_set_title('Unable to connect to database server');
     print theme('maintenance_page', '<p>If you still have to install Drupal, proceed to the <a href="'. base_path() .'install.php">installation page</a>.</p>
 <p>If you have already finished installed Drupal, this either means that the username and password information in your <code>settings.php</code> file is incorrect or that we can\'t connect to the MySQL database server. This could mean your hosting provider\'s database server is down.</p>
Index: database.mysqli.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.mysqli.inc,v
retrieving revision 1.44
diff -u -p -r1.44 database.mysqli.inc
--- database.mysqli.inc	3 Sep 2007 17:02:16 -0000	1.44
+++ database.mysqli.inc	17 Sep 2007 08:37:52 -0000
@@ -85,7 +85,7 @@ function db_connect($url) {
   // Find all database connection errors and error 1045 for access denied for user account
   if (mysqli_connect_errno() >= 2000 || mysqli_connect_errno() == 1045) {
     drupal_maintenance_theme();
-    drupal_set_header('HTTP/1.1 503 Service Unavailable');
+    drupal_http_status(503, 'Service Unavailable');
     drupal_set_title('Unable to connect to database server');
     print theme('maintenance_page', '<p>If you still have to install Drupal, proceed to the <a href="'. base_path() .'install.php">installation page</a>.</p>
 <p>If you have already finished installed Drupal, this either means that the username and password information in your <code>settings.php</code> file is incorrect or that we can\'t connect to the MySQL database server. This could mean your hosting provider\'s database server is down.</p>
Index: database.pgsql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.pgsql.inc,v
retrieving revision 1.62
diff -u -p -r1.62 database.pgsql.inc
--- database.pgsql.inc	2 Oct 2007 16:15:56 -0000	1.62
+++ database.pgsql.inc	8 Oct 2007 09:16:58 -0000
@@ -83,7 +83,7 @@ function db_connect($url) {
   $connection = @pg_connect($conn_string);
   if (!$connection) {
     drupal_maintenance_theme();
-    drupal_set_header('HTTP/1.1 503 Service Unavailable');
+    drupal_http_status(503, 'Service Unavailable');
     drupal_set_title('Unable to connect to database');
     print theme('maintenance_page', '<p>If you still have to install Drupal, proceed to the <a href="'. base_path() .'install.php">installation page</a>.</p>
 <p>If you have already finished installed Drupal, this either means that the username and password information in your <code>settings.php</code> file is incorrect or that we can\'t connect to the PostgreSQL database server. This could mean your hosting provider\'s database server is down.</p>
