[Rt-commit] rt branch, 4.2/psgi-wrap-for-plugins, created. rt-4.2.3-42-g1bbb2bc

Wallace Reis wreis at bestpractical.com
Thu Mar 20 12:21:52 EDT 2014


The branch, 4.2/psgi-wrap-for-plugins has been created
        at  1bbb2bc2e9b8c767b5bc1c5613915d2085d01846 (commit)

- Log -----------------------------------------------------------------
commit 122c9ffe6bffed80ecfebd431beeacf591d97006
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Wed Jul 24 11:43:45 2013 -0700

    Add means for plugins to wrap the PSGI app with their own arbitrary logic

diff --git a/lib/RT/Interface/Web/Handler.pm b/lib/RT/Interface/Web/Handler.pm
index 79cca99..078091f 100644
--- a/lib/RT/Interface/Web/Handler.pm
+++ b/lib/RT/Interface/Web/Handler.pm
@@ -313,7 +313,14 @@ sub PSGIApp {
                                             $self->CleanupRequest()
                                         });
     };
-    return $self->StaticWrap($mason);
+
+    my $app = $self->StaticWrap($mason);
+    for my $plugin (RT->Config->Get("Plugins")) {
+        my $wrap = $plugin->can("PSGIWrap")
+            or next;
+        $app = $wrap->($plugin, $app);
+    }
+    return $app;
 }
 
 sub StaticWrap {

commit 1bbb2bc2e9b8c767b5bc1c5613915d2085d01846
Author: Wallace Reis <wreis at bestpractical.com>
Date:   Thu Mar 20 13:21:00 2014 -0300

    Add tests for PSGIWrap API

diff --git a/t/data/plugins/RT-Extension-PSGIWrap/lib/RT/Extension/PSGIWrap.pm b/t/data/plugins/RT-Extension-PSGIWrap/lib/RT/Extension/PSGIWrap.pm
new file mode 100644
index 0000000..1d0a55e
--- /dev/null
+++ b/t/data/plugins/RT-Extension-PSGIWrap/lib/RT/Extension/PSGIWrap.pm
@@ -0,0 +1,16 @@
+package RT::Extension::PSGIWrap;
+
+use base 'Plack::Middleware';
+
+sub call {
+    my ( $self, $env ) = @_;
+    my $res = $self->app->($env);
+    return $self->response_cb( $res, sub {
+        my $headers = shift->[1];
+        Plack::Util::header_set($headers, 'X-RT-PSGIWrap' => '1');
+    } );
+}
+
+sub PSGIWrap { return shift->wrap(@_) }
+
+1;
diff --git a/t/web/psgi-wrap.t b/t/web/psgi-wrap.t
new file mode 100644
index 0000000..0e4b053
--- /dev/null
+++ b/t/web/psgi-wrap.t
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+
+use RT::Test
+    tests   => undef,
+    plugins => [qw(RT::Extension::PSGIWrap)];
+
+my ($base, $m) = RT::Test->started_ok;
+$m->login;
+ok(my $res = $m->get("/"));
+is($res->code, 200, 'Successful request to /');
+ok($res->header('X-RT-PSGIWrap'), 'X-RT-PSGIWrap header set from the plugin');
+
+undef $m;
+done_testing();

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


More information about the rt-commit mailing list