Do not set a redirect when streaming downloads. fixes file #11029

This commit is contained in:
Colin Kuskie 2009-09-23 21:27:43 -07:00
parent 564378bba8
commit 77fc01af38
3 changed files with 26 additions and 17 deletions

View file

@ -5,6 +5,7 @@
- fixed #11027: trash warning but no trash-limbo warning - fixed #11027: trash warning but no trash-limbo warning
- fixed #11031: AssetProxy refering to trash-limbo asset - fixed #11031: AssetProxy refering to trash-limbo asset
- fixed #11028: IOB: Not choosing status causes Problem With Request - fixed #11028: IOB: Not choosing status causes Problem With Request
- fixed #11029: enableStreamingUploads
7.8.0 7.8.0
- upgraded YUI to 2.8.0r4 - upgraded YUI to 2.8.0r4

View file

@ -656,19 +656,20 @@ When viewed directly, stream the stored file to the user.
=cut =cut
sub www_view { sub www_view {
my $self = shift; my $self = shift;
return $self->session->privilege->noAccess() unless $self->canView; my $session = $self->session;
return $session->privilege->noAccess() unless $self->canView;
# Check to make sure it's not in the trash or some other weird place # Check to make sure it's not in the trash or some other weird place
if ($self->get("state") ne "published") { if ($self->get("state") ne "published") {
my $i18n = WebGUI::International->new($self->session,'Asset_File'); my $i18n = WebGUI::International->new($session,'Asset_File');
$self->session->http->setStatus("404"); $session->http->setStatus("404");
return sprintf($i18n->get("file not found"), $self->getUrl()); return sprintf($i18n->get("file not found"), $self->getUrl());
} }
$self->session->http->setRedirect($self->getFileUrl); $session->http->setRedirect($self->getFileUrl) unless $session->config->get('enableStreamingUploads');
$self->session->http->setStreamedFile($self->getStorageLocation->getPath($self->get("filename"))); $session->http->setStreamedFile($self->getStorageLocation->getPath($self->get("filename")));
$self->session->http->sendHeader; $session->http->sendHeader;
return 'chunked'; return 'chunked';
} }

View file

@ -24,7 +24,7 @@ use WebGUI::Asset::File;
use Test::More; # increment this value for each test you create use Test::More; # increment this value for each test you create
use Test::Deep; use Test::Deep;
plan tests => 8; plan tests => 10;
#TODO: This script tests certain aspects of WebGUI::Storage and it should not #TODO: This script tests certain aspects of WebGUI::Storage and it should not
@ -32,7 +32,6 @@ my $session = WebGUI::Test->session;
##Create a storage location ##Create a storage location
my $storage = WebGUI::Storage->create($session); my $storage = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($storage);
##Save the image to the location ##Save the image to the location
my $filename = "someScalarFile.txt"; my $filename = "someScalarFile.txt";
@ -48,6 +47,7 @@ cmp_bag($storage->getFiles, ['someScalarFile.txt'], 'Only 1 file in storage with
$session->user({userId=>3}); $session->user({userId=>3});
my $versionTag = WebGUI::VersionTag->getWorking($session); my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"File Asset test"}); $versionTag->set({name=>"File Asset test"});
my $guard1 = cleanupGuard($versionTag);
my $properties = { my $properties = {
# '1234567890123456789012' # '1234567890123456789012'
id => 'FileAssetTest000000012', id => 'FileAssetTest000000012',
@ -85,15 +85,22 @@ $versionTag->commit;
############################################ ############################################
my $fileStorage = WebGUI::Storage->create($session); my $fileStorage = WebGUI::Storage->create($session);
WebGUI::Test->storagesToDelete($fileStorage); my $guard2 = cleanupGuard($fileStorage);
$mocker->set_always('getValue', $fileStorage->getId); $mocker->set_always('getValue', $fileStorage->getId);
my $fileFormStorage = $asset->getStorageFromPost(); my $fileFormStorage = $asset->getStorageFromPost();
isa_ok($fileFormStorage, 'WebGUI::Storage', 'Asset::File::getStorageFromPost'); isa_ok($fileFormStorage, 'WebGUI::Storage', 'Asset::File::getStorageFromPost');
END { ############################################
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { #
$versionTag->rollback; # www_view
} #
##Storage is cleaned up by rolling back the version tag ############################################
$fileStorage->delete;
} $session->config->set('enableStreamingUploads', '0');
$asset->www_view;
is($session->http->getRedirectLocation, $storage->getUrl('someScalarFile.txt'), 'www_view: sets a redirect');
$session->config->set('enableStreamingUploads', '1');
$session->http->setRedirectLocation('');
$asset->www_view;
is($session->http->getRedirectLocation, '', '... redirect not set when enableStreamingUploads is set');