[Rt-commit] rt branch, psgi, created. rt-3.9.4-129-g1778895

Chia-liang Kao clkao at bestpractical.com
Thu Oct 7 10:21:37 EDT 2010


The branch, psgi has been created
        at  1778895da5a6261a50a3553c52869502b0272ae1 (commit)

- Log -----------------------------------------------------------------
commit c8b55d04a170bf89b76c5ce8e714e641e5854a2d
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Thu Aug 12 23:45:56 2010 +0800

    psgi mason handler

diff --git a/lib/RT/Interface/Web/Request.pm b/lib/RT/Interface/Web/Request.pm
index 76e71a5..4e68740 100644
--- a/lib/RT/Interface/Web/Request.pm
+++ b/lib/RT/Interface/Web/Request.pm
@@ -53,18 +53,19 @@ use warnings;
 
 our $VERSION = '0.30';
 use base qw(HTML::Mason::Request);
+use Params::Validate qw(:all);
 
 sub new {
     my $class = shift;
 
-    my $new_class = $HTML::Mason::ApacheHandler::VERSION ?
-        'HTML::Mason::Request::ApacheHandler' :
-            $HTML::Mason::CGIHandler::VERSION ?
-                'HTML::Mason::Request::CGI' :
-                    'HTML::Mason::Request';
+    my $new_class =
+         $HTML::Mason::ApacheHandler::VERSION ? 'HTML::Mason::Request::ApacheHandler' :
+         $HTML::Mason::PSGIHandler::VERSION   ? 'HTML::Mason::Request::PSGI' :
+         $HTML::Mason::CGIHandler::VERSION    ? 'HTML::Mason::Request::CGI' :
+                                                'HTML::Mason::Request';
 
     $class->alter_superclass( $new_class );
-    $class->valid_params( %{ $new_class->valid_params } );
+    $class->valid_params( %{ $new_class->valid_params },cgi_request => { type => OBJECT, optional => 1 } );
     return $class->SUPER::new(@_);
 }
 

commit 1778895da5a6261a50a3553c52869502b0272ae1
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Thu Oct 7 22:24:19 2010 +0800

    psgi app.

diff --git a/app.psgi b/app.psgi
new file mode 100644
index 0000000..b4bbedd
--- /dev/null
+++ b/app.psgi
@@ -0,0 +1,101 @@
+# BEGIN BPS TAGGED BLOCK {{{
+# 
+# COPYRIGHT:
+# 
+# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
+#                                          <jesse at bestpractical.com>
+# 
+# (Except where explicitly superseded by other copyright notices)
+# 
+# 
+# LICENSE:
+# 
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+# 
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+# 
+# 
+# CONTRIBUTION SUBMISSION POLICY:
+# 
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+# 
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+# 
+# END BPS TAGGED BLOCK }}}
+use warnings;
+use strict;
+
+use File::Basename;
+eval {
+    require (dirname(__FILE__) .'/bin/webmux.pl');
+};
+if ($@) {
+    die "failed to load bin/webmux.pl: $@";
+}
+
+use HTML::Mason::PSGIHandler;
+use RT::Interface::Web::Handler;
+use CGI::Emulate::PSGI;
+use Plack::Request;
+
+use Encode qw(is_utf8 encode_utf8);
+
+my $h = RT::Interface::Web::Handler::NewHandler('HTML::Mason::PSGIHandler');
+my $handler = sub {
+    my $env = shift;
+    RT::ConnectToDatabase() unless RT->InstallMode;
+
+    my $req = Plack::Request->new($env);
+
+    unless ( $h->interp->comp_exists( $req->path_info ) ) {
+        my $path = $req->path_info;
+        $path .= '/' unless $path =~ m{/$};
+        $path .= 'index.html';
+        $env->{PATH_INFO} = $path
+            if $h->interp->comp_exists( $path );
+    }
+
+    my $ret;
+    {
+        # XXX: until we get rid of all $ENV stuff.
+        local %ENV = (%ENV, CGI::Emulate::PSGI->emulate_environment($env));
+
+        $ret = $h->handle_psgi($env);
+    }
+    $RT::Logger->crit($@) if $@ && $RT::Logger;
+    warn $@ if $@ && !$RT::Logger;
+    RT::Interface::Web::Handler->CleanupRequest();
+    if ($ret->[2] ) {
+        # XXX: for now.  the out_method for mason can be more careful
+        # and perhaps even streamy.  this should also check for
+        # explicit encoding in Content-Type header.
+        for (@{$ret->[2]}) { 
+            $_ = encode_utf8($_)
+                if is_utf8($_);
+        }
+    }
+    return $ret;
+};
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index 993ec68..9155f0d 100755
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -88,6 +88,7 @@ if ( $args{help} ) {
 # Set up defaults
 my %default = (
     'with-MASON' => 1,
+    'with-PSGI' => 1,
     'with-CORE' => 1,
     'with-CLI' => 1,
     'with-MAILGATE' => 1, 
@@ -230,6 +231,11 @@ JavaScript::Minifier
 IPC::Run3
 .
 
+$deps{'PSGI'} = [ text_to_hash( << '.') ];
+HTML::Mason::PSGIHandler
+Plack
+.
+
 $deps{'STANDALONE'} = [ text_to_hash( << '.') ];
 HTTP::Server::Simple 0.34
 HTTP::Server::Simple::Mason 0.14

-----------------------------------------------------------------------


More information about the Rt-commit mailing list