[cgiapp] CGI::Application::Server and
CGI::Application::Plugin::Stream
Bradley C Bailey
cgiapp at brad.memoryleak.org
Sun Dec 28 23:59:02 EST 2008
Hello,
I run my application under CGI::Application::Server during testing, and
recently began sending files with CGI::Application::Plugin::Stream.
However, they do not seem compatible since CAP::Stream directly prints
to STDOUT, and CA::Server runs under CGI_APP_RETURN_ONLY and expects the
application to return the content. So CAP::Stream prints the content
before CA::Server can print the proper HTTP stuff.
I attached a simple patch for a workaround, hopefully it goes through.
I am not sure this is the best solution though.
Comments?
Regards,
Bradley C Bailey
-------------- next part --------------
--- Stream.pm.orig 2008-12-28 21:49:47.000000000 -0700
+++ Stream.pm 2008-12-28 21:50:23.000000000 -0700
@@ -75,20 +75,27 @@
$self->header_add('-attachment' => $basename);
}
- $self->header_type( 'none' );
- print $self->query->header( $self->header_props() );
+ unless ($ENV{CGI_APP_RETURN_ONLY}) {
+ $self->header_type( 'none' );
+ print $self->query->header( $self->header_props() )
+ }
# This reads in the file in $byte size chunks
- my $first;
# File::MMagic may have read some of the file, so seek back to the beginning
+ my $output = "";
seek($fh,0,0);
while ( read( $fh, my $buffer, $bytes ) ) {
- print $buffer;
+ if ($ENV{CGI_APP_RETURN_ONLY}) {
+ $output .= $buffer;
+ } else {
+ print $buffer;
+ }
}
- print ''; # print a null string at the end
close ( $fh );
- return 1;
+ print '' unless $ENV{CGI_APP_RETURN_ONLY}; # print a null string at the end
+
+ return $ENV{CGI_APP_RETURN_ONLY} ? \$output : 1;
}
1;
More information about the cgiapp
mailing list