[Rt-commit] r5572 - in rt/branches/3.6-RELEASE: .

jesse at bestpractical.com jesse at bestpractical.com
Mon Jul 17 12:41:10 EDT 2006


Author: jesse
Date: Mon Jul 17 12:41:09 2006
New Revision: 5572

Modified:
   rt/branches/3.6-RELEASE/   (props changed)
   rt/branches/3.6-RELEASE/lib/RT/Interface/Web.pm

Log:
 r14053 at pinglin:  jesse | 2006-07-17 11:28:00 -0400
 * Added "Redirect" and "StaticFileHeaders" methods to RT::Interface::Web. 
 
 * Redirect is careful to redirect the browser to the same base RT url they're coming from
   and to close the user's Apache::Session, lest that module try to open two copies
   of the same prepared session database handle at the same time and fall over.
 
 * StaticFileHeaders tells the user's browser that the file being served
   was last modified at last server start and should be cached for approximately
   a month.  Better would be to use the Heuristics that Jifty::View::Static provides.
 
 


Modified: rt/branches/3.6-RELEASE/lib/RT/Interface/Web.pm
==============================================================================
--- rt/branches/3.6-RELEASE/lib/RT/Interface/Web.pm	(original)
+++ rt/branches/3.6-RELEASE/lib/RT/Interface/Web.pm	Mon Jul 17 12:41:09 2006
@@ -62,10 +62,12 @@
 =cut
 
 
-package RT::Interface::Web;
 use strict;
+use warnings;
 
-
+package RT::Interface::Web;
+use HTTP::Date;
+use URI;
 
 # {{{ EscapeUTF8
 
@@ -168,8 +170,57 @@
 # }}}
 
 
+
+=head2 Redirect URL
+
+This routine ells the current user's browser to redirect to URL.  
+Additionally, it unties the user's currently active session, helping to avoid 
+A bug in Apache::Session 1.81 and earlier which clobbers sessions if we try to use 
+a cached DBI statement handle twice at the same time.
+
+=cut
+
+
+sub Redirect {
+    my $redir_to = shift;
+    untie $HTML::Mason::Commands::session;
+    my $uri = URI->new($redir_to);
+    my $server_uri = URI->new($RT::WebURL);
+
+    # If the user is coming in via a non-canonical
+    # hostname, don't redirect them to the canonical host,
+    # it will just upset them (and invalidate their credentials)
+    if ($uri->host  eq $server_uri->host && 
+        $uri->port eq $server_uri->port) {
+            $uri->host($ENV{'HTTP_HOST'});
+            $uri->port($ENV{'SERVER_PORT'});
+        }
+
+    $HTML::Mason::Commands::m->redirect($uri->canonical);
+    $HTML::Mason::Commands::m->abort;
+}
+
+
+=head2 StaticFileHeaders 
+
+Send the browser a few headers to try to get it to (somewhat agressively)
+cache RT's static Javascript and CSS files.
+
+This routine could really use _accurate_ heuristics. (XXX TODO)
+
+=cut
+
+sub StaticFileHeaders {
+    # Expire things in a month.
+    $HTML::Mason::Commands::r->headers_out->{'Expires'} = HTTP::Date::time2str( time() + 2592000 );
+
+    # Last modified at server start time
+    $HTML::Mason::Commands::r->headers_out->{'Last-Modified'} = HTTP::Date::time2str($^T);
+
+}
+
+
 package HTML::Mason::Commands;
-use strict;
 use vars qw/$r $m %session/;
 
 


More information about the Rt-commit mailing list