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*
4.5.x
Steven Wittens 2004-07-29 01:41:33 +00:00
parent cd632f6251
commit 6c73823b10
1 changed files with 7 additions and 4 deletions

View File

@ -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() {