Index: bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.192
diff -u -r1.192 bootstrap.inc
--- bootstrap.inc	10 Sep 2007 12:19:11 -0000	1.192
+++ bootstrap.inc	17 Sep 2007 11:52:21 -0000
@@ -557,6 +557,35 @@
 }
 
 /**
+ * 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 @@
   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();
@@ -907,7 +936,7 @@
     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.687
diff -u -r1.687 common.inc
--- common.inc	15 Sep 2007 07:33:46 -0000	1.687
+++ common.inc	17 Sep 2007 10:15:32 -0000
@@ -306,7 +306,8 @@
   // Before the redirect, allow modules to react to the end of the page request.
   module_invoke_all('exit', $url);
 
-  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
@@ -319,7 +320,7 @@
  */
 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'))))));
@@ -329,8 +330,8 @@
  * 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
@@ -358,7 +359,7 @@
  * 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 -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 @@
   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 -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 @@
   // 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.60
diff -u -r1.60 database.pgsql.inc
--- database.pgsql.inc	14 Sep 2007 17:46:32 -0000	1.60
+++ database.pgsql.inc	17 Sep 2007 08:41:41 -0000
@@ -83,7 +83,7 @@
   $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>
