Re: possible bug in Mason 1.36

Scott Lanning <[email protected]> Wed, 22 Aug 2007 16:02:44 +0200 (CEST)
Newsgroups gmane.comp.web.mason.devel
Message-ID <[email protected]>
On Tue, 21 Aug 2007, Dave Rolsky wrote:
> My point was simply that while I don't understand how this code worked
> with Mason 1.35, there's no reason it shouldn't continue to work with 1.36

Mason checks twice in HTML::Mason::ApacheHandler whether to send headers
during the request in Bricolage:
1) in the _set_mason_req_out_method, where it builds the out_method sub,
for mod_perl1 it sends headers out and saves whether they've been
sent in a $sent_headers closure/static variable
2) in exec, one condition for calling $r->send_http_header
is !HTML::Mason::ApacheHandler::http_header_sent($r).
This is where the second header comes out.
http_header_sent does this

   sub http_header_sent { shift->headers_out->{"Content-type"} }

to supposedly determine if headers have been sent.

Mason version 1.35 behavior, Mason does $r->content_type(undef),
Dumper($r->headers_out):

$VAR1 = bless( {
                  'Set-Cookie' => 'BRICOLAGE_AUTH=....',
                  'Pragma' => 'no-cache',
                  'Cache-control' => 'no-cache',
                  'Connection' => 'close',
                  'Transfer-Encoding' => 'chunked',
                  'Content-Type' => 'text/html; charset=utf-8',
                  'Content-Language' => 'en_us',
                  'Expires' => 'Wed, 22 Aug 2007 13:11:21 GMT'
                }, 'Apache::Table' );

Content-Type is 'text/html; charset=utf-8',
so http_header_sent returns a true value.


Mason version 1.36 behavior, Mason does $r->content_type(''),
Dumper($r->headers_out):

$VAR1 = bless( {
                  'Set-Cookie' => 'BRICOLAGE_AUTH=....',
                  'Pragma' => 'no-cache',
                  'Cache-control' => 'no-cache',
                  'Connection' => 'close',
                  'Transfer-Encoding' => 'chunked',
                  'Content-Type' => '',
                  'Content-Language' => 'en_us',
                  'Expires' => 'Wed, 22 Aug 2007 13:12:49 GMT'
                }, 'Apache::Table' );

Content-Type is '',
so http_header_sent returns a false value.

In Apache, src/modules/perl/Apache.xs has

char *
content_type(r, ...)
     Apache	r

     CODE:
     get_set_PVp(r->content_type,r->pool);

     OUTPUT:
     RETVAL

where get_set_PVp is in src/modules/perl/mod_perl_xs.h

#define get_set_PVp(thing,p) \
     RETVAL = (char*)thing; \
     if(items > 1) \
         thing = (char*)(SvOK(ST(1)) ? pstrdup(p, SvPV(ST(1),na)) : NULL)

So passing undef or an empty string to $r->content_type
are apparently two different things, undef doing nothing,
empty string overwriting.
(Though I admit I'm a little confused. I think items == 2,
which is greater than 1, in both cases. So SvOK(ST(1)) will return
true if it's an empty string, false if it's undef, but don't those
both set `thing', which is a pointer to r->content_type ?)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/