From 6c73823b10bed9baebfa681967bc320f69b7d813 Mon Sep 17 00:00:00 2001 From: Steven Wittens Date: Thu, 29 Jul 2004 01:41:33 +0000 Subject: Fixing a rather nasty bug with page cache: The headers stored for cached pages ended in a newline, which caused header("") to get called when serving the page. On some PHP versions (happens on 4.3.3 at least, but not in 5.0), PHP adds a blank header to the HTTP request (i.e. just \r\n) which ends HTTP headers prematurely and adds a newline at the beginning of the page. This was not an issue before because we output HTML. Now that we have GZip compression, this bug caused corruption of the output. :P *phew* --- includes/common.inc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index 4ea42b449..9b8d6fcc6 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -162,13 +162,16 @@ function drupal_get_normal_path($path) { * @{ */ function drupal_set_header($header = NULL) { - static $stored_headers = ''; + // We use an array to guarantee there are no leading or trailing delimiters. + // This can cause header("") to get called when serving the page later, which + // ends HTTP headers prematurely on some PHP versions. + static $stored_headers = array(); - if (!is_null($header)) { + if (strlen($header)) { header($header); - $stored_headers .= $header ."\n"; + $stored_headers[] = $header; } - return $stored_headers; + return implode("\n", $stored_headers); } function drupal_get_headers() { -- cgit v1.2.3