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.
68 lines
1.9 KiB
Perl
68 lines
1.9 KiB
Perl
use strict;
|
|
use warnings;
|
|
use Test::More tests => 7;
|
|
|
|
use Plack::Test;
|
|
use Plack::Util;
|
|
use HTTP::Request::Common;
|
|
use WebGUI::Paths;
|
|
use WebGUI::Test;
|
|
|
|
# test things about responses
|
|
# this is like t/Session/Http.t but Plack specific
|
|
|
|
SKIP: {
|
|
skip 'set WEBGUI_LIVE to enable these tests', 7 unless $ENV{WEBGUI_LIVE};
|
|
|
|
my $session = WebGUI::Test->session;
|
|
|
|
my $prev_streaming_uploads = $session->config->get('enableStreamingUploads');
|
|
|
|
local $ENV{WEBGUI_CONFIG} = WebGUI::Test->file; # tell the share/site.psgi which site to load
|
|
|
|
#
|
|
# fire up a Plack to test streaming
|
|
#
|
|
|
|
$session->config->set('enableStreamingUploads', 1);
|
|
|
|
my $app = Plack::Util::load_psgi( WebGUI::Paths->defaultPSGI );
|
|
|
|
ok( $app, "created a PSGI app from app.psgi" );
|
|
|
|
test_psgi $app, sub {
|
|
my $cb = shift;
|
|
my $res = $cb->( GET "/root/import/gallery-templates/images/previous.gif" );
|
|
is $res->code, 200, 'enableStreamingUploads: 200 response';
|
|
is $res->header('Content-Type'), 'image/gif', '... content type is image/gif';
|
|
ok substr($res->content, 0, 100) =~ m/GIF89/, '... data contains the string GIF89';
|
|
};
|
|
|
|
|
|
#
|
|
# fire up another Plack to test non-streaming
|
|
#
|
|
|
|
$session->config->set('enableStreamingUploads', 0);
|
|
|
|
$app = Plack::Util::load_psgi( WebGUI::Paths->defaultPSGI );
|
|
|
|
my $redirect_url;
|
|
|
|
test_psgi $app, sub {
|
|
my $cb = shift;
|
|
my $res = $cb->( GET "/root/import/gallery-templates/images/previous.gif" );
|
|
is $res->code, 302, 'enableStreamingUploads: 302 response';
|
|
ok $res->header('Location'), '... Location header in response';
|
|
$res = $cb->(GET $res->header('Location') );
|
|
is $res->code, 200, '... following location, we get a 200 response code';
|
|
};
|
|
|
|
#
|
|
# put things back how they were
|
|
#
|
|
|
|
$session->config->set('enableStreamingUploads', $prev_streaming_uploads);
|
|
|
|
};
|
|
|