File assets should always give IO::File::WithPath objects to PSGI, instead of the current redirecting or streaming behavior. (#11688)

New API method:  WebGUI::Response::sendFile;  it, as appropriate, calls
setRedirect or setStreamedFile, depending on enableStreamingUploads config var.
setStreamedFile now kicks off the XSendfile process.
File.pm now uses this instead of trying to set both a redirect and a stream.
IO::File::WithPath blows up if a file doesn't exist so this raises an exception
now.
The http now no longer insist that '0' is not a valid filename to stream.
site.psgi, depending on enableStreamingUploads, enables either the Static
or XSendfile middleware.
This commit is contained in:
Scott Walters 2011-05-12 20:09:04 -04:00
parent 96bb194402
commit 7a994b59ce
6 changed files with 184 additions and 25 deletions

View file

@ -6,6 +6,7 @@ use WebGUI;
builder {
my $wg = WebGUI->new( config => $ENV{WEBGUI_CONFIG} );
my $config = $wg->config;
my $streaming_uploads = $config->get('enableStreamingUploads'); # have to restart for changes to this to take effect
enable 'Log4perl', category => $config->getFilename, conf => WebGUI::Paths->logConfig;
enable 'SimpleContentFilter', filter => sub {
@ -20,9 +21,13 @@ builder {
# For PassThru, use Plack::Builder::mount
# Extras fallback (you should be using something else to serve static files in production)
# Serve "Extras"
# Plack::Middleware::Static is fallback (you should be using something else to serve static files in production,
# unless you're using the corona Plack server, then it doesn't matter nearly so much)
my ( $extrasURL, $extrasPath ) = ( $config->get('extrasURL'), $config->get('extrasPath') );
enable 'Static', root => "$extrasPath/", path => sub {s{^\Q$extrasURL/}{}};
enable_if { $streaming_uploads } 'XSendfile';
enable_if { ! $streaming_uploads } 'Static', root => "$extrasPath/", path => sub {s{^\Q$extrasURL/}{}};
# Open/close the WebGUI::Session at the outer-most onion layer
enable '+WebGUI::Middleware::Session', config => $config;