Re: possible bug in Mason 1.36

Scott Lanning <[email protected]> Fri, 24 Aug 2007 16:03:42 +0200 (CEST)
Newsgroups gmane.comp.web.mason.devel
Message-ID <[email protected]>
On Thu, 23 Aug 2007, Dave Rolsky wrote:
> On Thu, 23 Aug 2007, Scott Lanning wrote:
> However, _before_ I do that I'd love to have a test case that
> demonstrates the current bug.

I tested to see if there's a difference between $r->content_type('')
and $r->content_type(undef), but it seems those actually work
as expected.... So I made a test case in Mason,
as you will see here.

At bottom of /etc/apache-perl/httpd.conf :
-----

PerlModule HappyHandler
<Location /happy>
   SetHandler perl-script
   PerlHandler HappyHandler
</Location>

-----
Contents of /usr/local/lib/site_perl/HappyHandler.pm ,
which is in perl -le'print "@INC"' :
-----

package HappyHandler;
use strict;
use warnings;
use HTML::Mason::ApacheHandler;
use Apache::Constants qw(:common);

my $ah = HTML::Mason::ApacheHandler->new(
     comp_root => '/var/www/happy',
     data_dir  => '/tmp/data',
     decline_dirs => 0,
);

sub handler {
     my ($r) = @_;

     $r->content_type('text/html; charset=utf-8');
     $ah->handle_request($r);

     return OK;
}

1;

-----
Contents of /var/www/happy/autohandler :
-----

% $m->call_next();

-----
Contents of /var/www/happy/dhandler :
-----

dhandler: '<% defined($r->content_type) ? $r->content_type : 'undef' %>'

-----


With HTML::Mason 1.36, this is the output at
http://localhost/happy :
-----

dhandler: ''
HTTP/1.1 200 OK
Date: Fri, 24 Aug 2007 13:53:19 GMT
Server: Apache/1.3.34 (Ubuntu) PHP/4.4.2-1build1 mod_perl/1.29
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive, Keep-Alive
Transfer-Encoding: chunked, chunked
Content-Type:

-----
The component has an empty string as the Content-type,
and an additional set of headers is output.
But if I apply the following patch,
-----

--- /usr/local/share/perl/5.8.7/HTML/Mason/ApacheHandler.pm~    2007-08-22 
12:15:31.000000000 +0200
+++ /usr/local/share/perl/5.8.7/HTML/Mason/ApacheHandler.pm     2007-08-24 
15:54:00.000000000 +0200
@@ -951,7 +951,8 @@
      my $is_dir = -d $r->filename;

      if ($is_dir && !$self->decline_dirs) {
-        $r->content_type('');
+#        $r->content_type('');
+        $r->content_type(undef);
      }
      return $is_dir ? 'dir' : -f _ ? 'file' : 'other';
  }

-----
then this is the output at http://localhost/happy :
-----

dhandler: 'undef'

-----

That is, the Content-type is undef, and no additional
set of headers is output. Q.E.D. :)

-------------------------------------------------------------------------
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/