Beaudet, David P.
2007-08-06 20:09:10 UTC
I discovered that under Apache 1.3 (running the Bricolage CMS), HTTP
headers are getting sent twice - once correctly, and once after the page
has been sent back to the browser. As a result, I'm getting HTTP
headers displayed in the HTML for certain pages. Downgrading to Mason
1.35 fixes the problem. I believe this problem only appears under
Apache 1.x.
I think there might be a bug in Mason's ApacheHandler.pm, line 954,
introduced with version 1.36.
Here's what I think is going on:
(1) ApacheHandler.pm, line 954: content_type('') is accepted by Apache
as an empty string (which might be invalid in its own right, but unsure)
and is output as an empty string when the Mason OUT method sends the
content type via send_http_header() the first through.
(2) Further down the chain, ApacheHandler.pm's http_header_sent() method
checks the value of the "Content-Type" header against undef to see
whether the headers were already sent and receives undef back, so the
fact that the header was already sent with ('') as content_type is not
registered.
(3) So, EXEC happily sends a second header with a blank Content-Type.
Resolution:
Changing line 954 from $r->content_type('') back to what it used to be
in 1.35 $r->content_type(undef) fixes the duplicate header problem.
There's no documentation I could find explaining why that was changed in
1.36.
Here's a patch, in case it is in fact a bug that can be fixed in the
next release.
--- ./ApacheHandler.pm 2007-08-06 16:01:08.000000000 -0400
+++ ./ApacheHandler.pm 2007-08-06 16:05:16.000000000 -0400
@@ -951,7 +951,7 @@
my $is_dir = -d $r->filename;
if ($is_dir && !$self->decline_dirs) {
- $r->content_type('');
+ $r->content_type(undef);
}
return $is_dir ? 'dir' : -f _ ? 'file' : 'other';
}
headers are getting sent twice - once correctly, and once after the page
has been sent back to the browser. As a result, I'm getting HTTP
headers displayed in the HTML for certain pages. Downgrading to Mason
1.35 fixes the problem. I believe this problem only appears under
Apache 1.x.
I think there might be a bug in Mason's ApacheHandler.pm, line 954,
introduced with version 1.36.
Here's what I think is going on:
(1) ApacheHandler.pm, line 954: content_type('') is accepted by Apache
as an empty string (which might be invalid in its own right, but unsure)
and is output as an empty string when the Mason OUT method sends the
content type via send_http_header() the first through.
(2) Further down the chain, ApacheHandler.pm's http_header_sent() method
checks the value of the "Content-Type" header against undef to see
whether the headers were already sent and receives undef back, so the
fact that the header was already sent with ('') as content_type is not
registered.
(3) So, EXEC happily sends a second header with a blank Content-Type.
Resolution:
Changing line 954 from $r->content_type('') back to what it used to be
in 1.35 $r->content_type(undef) fixes the duplicate header problem.
There's no documentation I could find explaining why that was changed in
1.36.
Here's a patch, in case it is in fact a bug that can be fixed in the
next release.
--- ./ApacheHandler.pm 2007-08-06 16:01:08.000000000 -0400
+++ ./ApacheHandler.pm 2007-08-06 16:05:16.000000000 -0400
@@ -951,7 +951,7 @@
my $is_dir = -d $r->filename;
if ($is_dir && !$self->decline_dirs) {
- $r->content_type('');
+ $r->content_type(undef);
}
return $is_dir ? 'dir' : -f _ ? 'file' : 'other';
}