[Rt-commit] rt branch, 4.2/static-js, updated. rt-4.1.6-28-ge5dfb03

Thomas Sibley trs at bestpractical.com
Thu Feb 14 21:34:47 EST 2013


The branch, 4.2/static-js has been updated
       via  e5dfb03d71442fb6dc5b10b7750606e5ba5cd6b9 (commit)
      from  54a3c813ef0d44a164bdfc4931319ea12397b26b (commit)

Summary of changes:
 lib/RT/Squish/JS.pm          | 26 +++++++++++++-------------
 sbin/rt-test-dependencies.in |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)

- Log -----------------------------------------------------------------
commit e5dfb03d71442fb6dc5b10b7750606e5ba5cd6b9
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Feb 14 18:25:23 2013 -0800

    Use a pure Plack and HTTP::Message solution for internal PSGI requests
    
    Replaces LWP::Protocol::PSGI and the complexity wrapped up in that
    module with a much more straightforward approach.  Since we're writing
    new code — not pulling the PSGI-wool over the eyes of otherwise
    unsuspecting code — we don't need the cloak of LWP.
    
    A nice side benefit is that without LWP::Protocol::PSGI, there are no
    warnings when LWP::Protocol::https isn't installed.  Thus, we won't need
    to either require it for the squishing functionality or suppress the
    warning with ugly warning handlers.

diff --git a/lib/RT/Squish/JS.pm b/lib/RT/Squish/JS.pm
index 70654d0..b2a7dfd 100644
--- a/lib/RT/Squish/JS.pm
+++ b/lib/RT/Squish/JS.pm
@@ -65,8 +65,9 @@ use warnings;
 package RT::Squish::JS;
 use base 'RT::Squish';
 
-use LWP::Simple ();
-use LWP::Protocol::PSGI;
+use HTTP::Message::PSGI;
+use HTTP::Request;
+use HTTP::Response;
 
 =head2 Squish
 
@@ -77,26 +78,25 @@ not only concatenate files, but also minify them
 sub Squish {
     my $self    = shift;
     my $content = "";
-
-    LWP::Protocol::PSGI->register(
-        RT::Interface::Web::Handler->StaticWrap(
-            # Anything the static wrap doesn't handle gets 404'd.
-            sub { [404, [], []] }
-        )
+    my $static  = RT::Interface::Web::Handler->StaticWrap(
+        # Anything the static wrap doesn't handle gets 404'd.
+        sub { [404, [], []] }
     );
 
     for my $file ( RT::Interface::Web->JSFiles ) {
-        my $uri = "http://psgi-internal/static/js/$file";
+        my $uri = "/static/js/$file";
+        my $res = HTTP::Response->from_psgi(
+            $static->( HTTP::Request->new(GET => $uri)->to_psgi )
+        );
 
-        if (defined(my $js = LWP::Simple::get($uri))) {
-            $content .= $js;
+        if ($res->is_success) {
+            $content .= $res->decoded_content;
         } else {
-            RT->Logger->error("Unable to fetch $uri for JS Squishing");
+            RT->Logger->error("Unable to fetch $uri for JS Squishing: " . $res->status_line);
             next;
         }
     }
 
-    LWP::Protocol::PSGI->unregister;
     return $self->Filter($content);
 }
 
diff --git a/sbin/rt-test-dependencies.in b/sbin/rt-test-dependencies.in
index 827f00b..18675b5 100644
--- a/sbin/rt-test-dependencies.in
+++ b/sbin/rt-test-dependencies.in
@@ -230,6 +230,7 @@ Regexp::IPv6
 Symbol::Global::Name
 HTML::Entities
 Role::Basic 0.12
+HTTP::Message 6.00
 .
 
 $deps{'MASON'} = [ text_to_hash( << '.') ];
@@ -254,7 +255,6 @@ HTML::Mason::PSGIHandler 0.52
 Plack 0.9971
 Plack::Handler::Starlet
 CGI::Emulate::PSGI
-LWP::Protocol::PSGI
 .
 
 $deps{'MAILGATE'} = [ text_to_hash( << '.') ];

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


More information about the Rt-commit mailing list