[Rt-commit] r2822 - in HTTP-Server-Simple-Mason: . lib/HTTP/Server/Simple

jesse at bestpractical.com jesse at bestpractical.com
Mon May 2 22:14:43 EDT 2005


Author: jesse
Date: Mon May  2 22:14:42 2005
New Revision: 2822

Added:
   HTTP-Server-Simple-Mason/Changes
Modified:
   HTTP-Server-Simple-Mason/   (props changed)
   HTTP-Server-Simple-Mason/Makefile.PL
   HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm
Log:
 r14712 at hualien:  jesse | 2005-05-02 22:14:02 -0400
 * Added support for redirects; 0.05


Added: HTTP-Server-Simple-Mason/Changes
==============================================================================
--- (empty file)
+++ HTTP-Server-Simple-Mason/Changes	Mon May  2 22:14:42 2005
@@ -0,0 +1,3 @@
+0.05 Mon May  2 22:12:15 EDT 2005
+
+* Added support for redirects. (Also, added a Hook::LexWrap dependency)

Modified: HTTP-Server-Simple-Mason/Makefile.PL
==============================================================================
--- HTTP-Server-Simple-Mason/Makefile.PL	(original)
+++ HTTP-Server-Simple-Mason/Makefile.PL	Mon May  2 22:14:42 2005
@@ -6,7 +6,8 @@
 license('perl');
 abstract('A simple mason server');
 requires( HTTP::Server::Simple => 0.04,
-          HTML::Mason => 1.25
+          HTML::Mason => 1.25,
+          Hook::LexWrap => 0
       );
 
 &WriteAll;

Modified: HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm
==============================================================================
--- HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm	(original)
+++ HTTP-Server-Simple-Mason/lib/HTTP/Server/Simple/Mason.pm	Mon May  2 22:14:42 2005
@@ -1,7 +1,7 @@
 package HTTP::Server::Simple::Mason;
 use base qw/HTTP::Server::Simple::CGI/;
 use strict;
-our $VERSION = '0.03';
+our $VERSION = '0.05';
 
 =head1 NAME
 
@@ -42,6 +42,16 @@
 
 
 use HTML::Mason::CGIHandler;
+use HTML::Mason::FakeApache;
+
+use Hook::LexWrap;
+
+wrap 'HTML::Mason::FakeApache::send_http_header', pre => sub {
+    my $r = shift;
+    my $status = $r->header_out('Status') || '200 H::S::Mason OK';
+    print STDOUT "HTTP/1.0 $status\n";
+};
+
 
 sub mason_handler {
     my $self = shift;
@@ -71,20 +81,50 @@
         $cgi->path_info( $cgi->path_info . "/index.html" );
     }
 
-            print <<EOF;
-HTTP/1.0 200 OK
-Content-Type: text/html
-EOF
 
-    eval { $self->mason_handler->handle_cgi_object($cgi); };
+    eval { my $m = $self->mason_handler;
+
+        $m->handle_cgi_object($cgi) };
 }
 
+
+
 sub new_handler {
     my $self    = shift;
     my $handler = HTML::Mason::CGIHandler->new(
         $self->default_mason_config,
         $self->mason_config,
-        @_
+   # Override mason's default output method so 
+   # we can change the binmode to our encoding if
+   # we happen to be handed character data instead
+   # of binary data.
+   # 
+   # Cloned from HTML::Mason::CGIHandler
+    out_method => 
+      sub {
+            my $m = HTML::Mason::Request->instance;
+            my $r = $m->cgi_request;
+            # Send headers if they have not been sent by us or by user.
+            # We use instance here because if we store $request we get a
+            # circular reference and a big memory leak.
+                unless ($r->http_header_sent) {
+                       $r->send_http_header();
+                }
+            {
+            $r->content_type || $r->content_type('text/htm'); # Set up a default
+
+            if ($r->content_type =~ /charset=([\w-]+)$/ ) {
+                my $enc = $1;
+                binmode *STDOUT, ":encoding($enc)";
+            }
+            # We could perhaps install a new, faster out_method here that
+            # wouldn't have to keep checking whether headers have been
+            # sent and what the $r->method is.  That would require
+            # additions to the Request interface, though.
+             print STDOUT grep {defined} @_;
+            }
+        },
+        @_,
     );
 
     $handler->interp->set_escape(


More information about the Rt-commit mailing list