Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.765
diff -u -p -r1.765 common.inc
--- includes/common.inc	6 May 2008 12:18:45 -0000	1.765
+++ includes/common.inc	9 May 2008 09:20:29 -0000
@@ -130,25 +130,36 @@ function drupal_clear_path_cache() {
  *
  * Note: When sending a Content-Type header, always include a 'charset' type,
  * too. This is necessary to avoid security bugs (e.g. UTF-7 XSS).
+ *
+ * @param $header The header to set.
+ * @param $replace Whether to replace an existing similar header.
+ *
+ * @return An array of header => value pairs.
  */
-function drupal_set_header($header = NULL) {
+function drupal_set_header($header = NULL, $replace = FALSE) {
   // We use an array to guarantee there are no leading or trailing delimiters.
   // Otherwise, header('') could get called when serving the page later, which
   // ends HTTP headers prematurely on some PHP versions.
   static $stored_headers = array();
 
   if (strlen($header)) {
-    header($header);
-    $stored_headers[] = $header;
+    header($header, $replace);
+    $header = explode(' ', $header, 2);
+    $stored_headers[$header[0]] = $header[1];
   }
-  return implode("\n", $stored_headers);
+  return $stored_headers;
 }
 
 /**
  * Get the HTTP response headers for the current page.
  */
 function drupal_get_headers() {
-  return drupal_set_header();
+  $headers = drupal_set_header();
+  $header = '';
+  foreach ($headers as $name => $value) {
+    $header .= "$name $value\n";
+  }
+  return $header;
 }
 
 /**
