[Rt-commit] r17436 - in rt/3.8/trunk: . lib/RT/Interface/Web/Mason share/html/Elements share/html/NoAuth
falcone at bestpractical.com
falcone at bestpractical.com
Tue Dec 30 13:24:43 EST 2008
Author: falcone
Date: Tue Dec 30 13:24:43 2008
New Revision: 17436
Added:
rt/3.8/trunk/share/html/Elements/SendStaticFile
rt/3.8/trunk/share/html/NoAuth/SendStaticFile
Modified:
rt/3.8/trunk/ (props changed)
rt/3.8/trunk/lib/RT/Interface/Web.pm
rt/3.8/trunk/lib/RT/Interface/Web/Mason/CGIHandler.pm
Log:
r42942 at ketch: falcone | 2008-12-30 13:15:55 -0500
* Rework CGIHandler to invoke a mason shim that serves image files
This works under the standalone servers and fcgi
Modified: rt/3.8/trunk/lib/RT/Interface/Web.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Interface/Web.pm (original)
+++ rt/3.8/trunk/lib/RT/Interface/Web.pm Tue Dec 30 13:24:43 2008
@@ -237,6 +237,34 @@
# $HTML::Mason::Commands::r->headers_out->{'Last-Modified'} = $date->RFC2616;
}
+=head2 SendStaticFile
+
+=cut
+
+sub SendStaticFile {
+ my $self = shift;
+ my %args = @_;
+ my $file = $args{File};
+ my $type = $args{Type};
+
+ unless ( $type ) {
+ if ($file =~ /\.(gif|png|jpe?g)$/i) {
+ $type = "image/$1";
+ $type =~ s/jpg/jpeg/gi;
+ }
+ $type ||= "application/octet-stream";
+ }
+ $HTML::Mason::Commands::r->content_type($type);
+ open my $fh, "<$file" or die "couldn't open file: $!";
+ binmode($fh);
+ {
+ local $/ = \16384;
+ $HTML::Mason::Commands::m->out($_) while (<$fh>);
+ $HTML::Mason::Commands::m->flush_buffer;
+ }
+ close $fh;
+}
+
sub StripContent {
my %args = @_;
my $content = $args{Content};
Modified: rt/3.8/trunk/lib/RT/Interface/Web/Mason/CGIHandler.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Interface/Web/Mason/CGIHandler.pm (original)
+++ rt/3.8/trunk/lib/RT/Interface/Web/Mason/CGIHandler.pm Tue Dec 30 13:24:43 2008
@@ -12,16 +12,15 @@
my ($self, $cgi) = @_;
if (my ($file, $type) = $self->image_file_request($cgi->path_info)) {
- print $cgi->header(-type => $type,
- -Content_length => (-s $file) );
- open my $fh, "<$file" or die "Can't open $file: $!";
- binmode($fh);
+ # Mason will pick the component off of the pathinfo
+ # and we need to trick it into taking arguments since other
+ # options like handle_comp don't take args and exec needs
+ # us to set up $m and $r by hand
+ $cgi->param(-name => 'File', -value => $file);
+ $cgi->param(-name => 'Type', -value => $type);
+ $cgi->path_info('/NoAuth/SendStaticFile');
+ $self->SUPER::handle_cgi_object($cgi);
- # Read 16384 byte chunks instead of splitting on newlines (so it works
- # better for binary files)
- local $/ = \16384;
- print $_ while <$fh>;
- close $fh;
return;
}
Added: rt/3.8/trunk/share/html/Elements/SendStaticFile
==============================================================================
--- (empty file)
+++ rt/3.8/trunk/share/html/Elements/SendStaticFile Tue Dec 30 13:24:43 2008
@@ -0,0 +1,13 @@
+<%INIT>
+&RT::Interface::Web::StaticFileHeaders();
+
+die "file $File not found" unless -f $File && -r _;
+
+RT::Interface::Web->SendStaticFile( File => $File, Type => $Type );
+
+$m->abort;
+</%INIT>
+<%ARGS>
+$File
+$Type => undef
+</%ARGS>
Added: rt/3.8/trunk/share/html/NoAuth/SendStaticFile
==============================================================================
--- (empty file)
+++ rt/3.8/trunk/share/html/NoAuth/SendStaticFile Tue Dec 30 13:24:43 2008
@@ -0,0 +1,3 @@
+%# shim for CGIHandler to avoid tripping the autohandler
+%# on things in NoAuth
+<& /Elements/SendStaticFile, %ARGS &>
More information about the Rt-commit
mailing list