From dd6a297c069de4d0a11b55267969a36f93445f75 Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Tue, 10 May 2011 13:58:44 -0400 Subject: [PATCH 1/7] make the admin view [Edit] controls right-click-able so I can continue to right-click-open-in-new-tab them. --- www/extras/admin/toolbar.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/extras/admin/toolbar.js b/www/extras/admin/toolbar.js index bfa29e892..72421a7e6 100644 --- a/www/extras/admin/toolbar.js +++ b/www/extras/admin/toolbar.js @@ -100,9 +100,10 @@ WebGUI.Toolbar.prototype.render // Edit button var editButton = new YAHOO.widget.Button({ - type : "push", + type : "link", "container" : this.container, label : assetData.helpers["edit"].label, + href : assetData.helpers["edit"].url, onclick : { fn: window.parent.admin.getHelperHandler( this.assetId, "edit", assetData.helpers["edit"] ) } From 2d31f7234a368b17a5090e682593dd57b1e130e3 Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Tue, 10 May 2011 14:26:16 -0400 Subject: [PATCH 2/7] PSGI entry points (#11632) -- add a plackMiddleware section to the config file; modify share/site.psgi to load from it. This is minimal in implementation right now in that there's no support for passing args, which would generally be objects mixed with strings, to the middlewares being added, as would be necessary if the .psgi files were to be largely migrated to the config files. I agree that it's important that upgrade scripts be able to add middleware (probably custom ones that know how to get the session from %$env) but I'm not convinced of the utility of moving much logic out of share/site.psgi. --- share/site.psgi | 6 +++++ t/PSGI/ConfigMiddleware.t | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 t/PSGI/ConfigMiddleware.t diff --git a/share/site.psgi b/share/site.psgi index da9b5b8ff..9c553b73a 100644 --- a/share/site.psgi +++ b/share/site.psgi @@ -56,6 +56,12 @@ builder { Plack::App::File->new(root => $config->get('uploadsPath')); }; + # enable config defined Middleware + + for my $mw ( @{ $config->get('plackMiddleware') || [] } ) { + enable $mw; + } + # Return the app mount '/' => $wg->to_app; }; diff --git a/t/PSGI/ConfigMiddleware.t b/t/PSGI/ConfigMiddleware.t new file mode 100644 index 000000000..0555e04c0 --- /dev/null +++ b/t/PSGI/ConfigMiddleware.t @@ -0,0 +1,46 @@ +use strict; +use warnings; +use Test::More tests => 3; + +use Plack::Test; +use Plack::Util; +use HTTP::Request::Common; +use WebGUI::Paths; +use WebGUI::Test; + +SKIP: { + skip 'set WEBGUI_LIVE to enable these tests', 3 unless $ENV{WEBGUI_LIVE}; + + my $session = WebGUI::Test->session; + $session->config->addToArray( 'plackMiddleware', '+WebGUI::Middleware::SHOUTING' ); + + local $ENV{WEBGUI_CONFIG} = WebGUI::Test->file; # tell the share/site.psgi which site to load + + 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 "/home" ); + is $res->code, 200, 'able to fetch pages with WebGUI::Middleware::SHOUTING installed'; + like $res->content, qr/EASY TO USE WEB APPLICATION FRAMEWORK/, 'contains the text "EASY TO USE WEB APPLICATION FRAMEWORK"'; + }; + + $session->config->deleteFromArray( 'plackMiddleware', '+WebGUI::Middleware::SHOUTING' ); +} + +package WebGUI::Middleware::SHOUTING; +BEGIN { $INC{'WebGUI/Middleware/SHOUTING.pm'} = __FILE__; }; + +use parent 'Plack::Middleware'; + +sub call { + my($self, $env) = @_; + my $res = $self->app->($env); + for ( ref $res->[2] ? @{ $res->[2] } : ( $res->[2] ) ) { + s{>(.*?)<}{'>' . uc($1) . '<'}gse; + } + return $res; +} + From d2c86700980807ce9ab9f4e48d5660a9f40ab9ab Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Wed, 11 May 2011 13:58:20 -0400 Subject: [PATCH 3/7] Introduce WebGUI::Test::getPage2, similar to WebGUI::Test::getPage, that makes requests using Plack::Test and attempts to maintain getPage's API. Change three tests in t/Asset/AssetExportHtml.t to use this instead. Backstory: Forthcoming WebGUI::Session::HTTP, ::Request, ::Responses mucking abouts broke some tests that use WebGUI::Test::getPage; in the case of t/Asset/AssetExportHtml.t, files were written correctly to disc but tests failed because it was comparing them to undef, which it got back for the page, apparently because getPage bypasses the logic that traps printing to a filehandle. --- lib/WebGUI/Test.pm | 91 +++++++++++++++++++++++++++++++++++++++ t/Asset/AssetExportHtml.t | 25 ++++++----- 2 files changed, 106 insertions(+), 10 deletions(-) diff --git a/lib/WebGUI/Test.pm b/lib/WebGUI/Test.pm index 2fd561098..2eb15b6ed 100644 --- a/lib/WebGUI/Test.pm +++ b/lib/WebGUI/Test.pm @@ -46,6 +46,12 @@ use WebGUI::Paths -inc; use namespace::clean; use WebGUI::User; +use Plack::Test; +use Plack::Util; +use HTTP::Request::Common; +use WebGUI::GUID; + + our @EXPORT = qw(cleanupGuard addToCleanup); our @EXPORT_OK = qw(session config collateral); @@ -377,6 +383,7 @@ below. # I think that getPage should be entirely replaced with calles to Plack::Test::test_psgi # - testing with the callback is better and it means we can run on any backend +# I agree. sub getPage { my $class = shift; my $actor = shift; # The actor to work on @@ -431,6 +438,90 @@ sub getPage { return join '', @{$session->response->body}; } +=head2 getPage2 ( request|url [, opts] ) + +Get the entire response from a page request using L. + +Accepts an L object as an argument, which cooked up auth info will be added to. +An L will be constructed from a simple relative URL such as C if a string is passed instead. + +Returns an L object on which you may call C<< decoded_content() >> to get the body content as a string. +C is a hash reference of options with keys outlined below. + + user => A user object to set for this request + userId => A userId to set for this request + formParams => A hash reference of form parameters + +Compared to C above, these are not yet supported: + + uploads + args + +=cut + +sub getPage2 { + my $class = shift; + my $request = shift; + my $optionsRef = shift; # A hashref of options + # args => Array ref of args to the page sub + # user => A user object to set + # userId => A user ID to set, "user" takes + # precedence + + die "not supported" if exists $optionsRef->{args}; + die "not supported" if exists $optionsRef->{formParams}; + die "not supported" if exists $optionsRef->{uploads}; + + my $session = $CLASS->session; + + # Save state + my $oldUser = $session->user; + my $oldRequest = $session->request; + + # Set the appropriate user + if ($optionsRef->{user}) { + $session->user({ user => $optionsRef->{user} }); + } + elsif ($optionsRef->{userId}) { + $session->user({ userId => $optionsRef->{userId} }); + } + $session->user->uncache; + + # Fake up a logged in session + my $wgSession = WebGUI::GUID->generate; + $session->db->write(qq{ + replace into userSession (sessionId, expires, lastPageView, userId) + values (?, ?, ?, ?) + }, [ + $wgSession, scalar time + 60 * 20, scalar time, $session->user->userId, + ] ) or die; + + my $response; + + # Create a new request object, or fix up the one given to us + if( ! eval { $request->isa('HTTP::Request') } ) { + if( $optionsRef->{formParams} ) { + $request = HTTP::Request::Common::POST( "http://127.0.0.1/$request", [ %{ $optionsRef->{formParams} } ] ) or die; + } else { + $request = HTTP::Request->new( GET => "http://127.0.0.1/$request" ) or die; + } + } + $request->header( 'Set-Cookie3' => qq{wgSession=$wgSession; path="/"; domain=127.0.0.1; path_spec; discard; version=0} ); + + my $app = Plack::Util::load_psgi( WebGUI::Paths->defaultPSGI ) or die; + + test_psgi $app, sub { + my $cb = shift; + $response = $cb->( $request ); + }; + + # Restore the former user and request + $session->user({ user => $oldUser }); + $session->{_request} = $oldRequest; # dubious about this; if we're going to try to support requests inside of other requests, it should be tested and actually supported rather than just some optimistic arm waving done + + return $response; +} + #---------------------------------------------------------------------------- =head2 getTestCollateralPath ( [filename] ) diff --git a/t/Asset/AssetExportHtml.t b/t/Asset/AssetExportHtml.t index 58b9673c7..94914c6df 100644 --- a/t/Asset/AssetExportHtml.t +++ b/t/Asset/AssetExportHtml.t @@ -378,7 +378,7 @@ is($fileAsPath->absolute($exportPath)->stringify, $litmus->absolute($exportPath) # we need to be tricky here and call code in wG proper which calls www_ methods # even though we don't have access to modperl. the following hack lets us do # that. -#$session->http->setNoHeader(1); +#$session->response->setNoHeader(1); $session->user( { userId => 1 } ); my $content; @@ -392,7 +392,12 @@ is($@, '', "exportWriteFile works when creating exportPath"); ok(-e $parent->exportGetUrlAsPath->absolute->stringify, "exportWriteFile actually writes the file when creating exportPath"); # now make sure that it contains the correct content -eval { $content = WebGUI::Test->getPage($parent, 'exportHtml_view', { user => WebGUI::User->new($session, 1) } ) }; +eval { + $content = WebGUI::Test->getPage2( + $parent->get('url').'?func=exportHtml_view', + { user => WebGUI::User->new($session, 1) }, + )->decoded_content +}; is(scalar $parent->exportGetUrlAsPath->slurp, $content, "exportWriteFile puts the correct contents in exported parent"); @@ -405,7 +410,7 @@ my $unwritablePath = Path::Class::Dir->new($config->get('uploadsPath'), 'temp', chmod 0000, $guidPath->stringify; $config->set('exportPath', $unwritablePath->absolute->stringify); -$session->http->setNoHeader(1); +$session->response->setNoHeader(1); SKIP: { skip 'Root will cause this test to fail since it does not obey file permissions', 2 if $< == 0; @@ -436,7 +441,7 @@ $config->set('exportPath', $guidPath->absolute->stringify); chmod 0755, $guidPath->stringify; $unwritablePath->remove; -$session->http->setNoHeader(1); +$session->response->setNoHeader(1); eval { $firstChild->exportWriteFile() }; is($@, '', "exportWriteFile works for first_child"); @@ -444,14 +449,14 @@ is($@, '', "exportWriteFile works for first_child"); ok(-e $firstChild->exportGetUrlAsPath->absolute->stringify, "exportWriteFile actually writes the first_child file"); # verify it has the correct contents -eval { $content = WebGUI::Test->getPage($firstChild, 'exportHtml_view') }; +eval { $content = WebGUI::Test->getPage2( $firstChild->get('url').'?func=exportHtml_view', )->decoded_content }; is(scalar $firstChild->exportGetUrlAsPath->absolute->slurp, $content, "exportWriteFile puts the correct contents in exported first_child"); # and one more level. remove the export path to ensure directory creation keeps # working. $guidPath->rmtree; -$session->http->setNoHeader(1); +$session->response->setNoHeader(1); $session->user( { userId => 1 } ); eval { $grandChild->exportWriteFile() }; is($@, '', "exportWriteFile works for grandchild"); @@ -461,13 +466,13 @@ ok(-e $grandChild->exportGetUrlAsPath->absolute->stringify, "exportWriteFile act # finally, check its contents $session->style->sent(0); -eval { $content = WebGUI::Test->getPage($grandChild, 'exportHtml_view') }; +eval { $content = WebGUI::Test->getPage2( $grandChild->get('url').'?func=exportHtml_view', )->decoded_content }; is(scalar $grandChild->exportGetUrlAsPath->absolute->slurp, $content, "exportWriteFile puts correct content in exported grandchild"); # test different extensions $guidPath->rmtree; $asset = WebGUI::Asset->newById($session, 'ExportTest000000000001'); -$session->http->setNoHeader(1); +$session->response->setNoHeader(1); eval { $asset->exportWriteFile() }; is($@, '', 'exportWriteFile for perl file works'); @@ -488,7 +493,7 @@ $guidPath->rmtree; # isn't allowed to see. this means that we'll need to temporarily change the # permissions on something. $parent->update( { groupIdView => 3 } ); # admins -$session->http->setNoHeader(1); +$session->response->setNoHeader(1); eval { $parent->exportWriteFile() }; $e = Exception::Class->caught(); isa_ok($e, 'WebGUI::Error', "exportWriteFile throws when user can't view asset"); @@ -912,7 +917,7 @@ SKIP: { # user can't view asset $parent->update( { groupIdView => 3 } ); -$session->http->setNoHeader(1); +$session->response->setNoHeader(1); chmod 0755, $tempDirectory; eval { ($message) = $parent->exportAsHtml( { userId => 1, depth => 99 } ) }; From 72bac90f93b827c90c0a46fb5a6d15ea120f6a70 Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Wed, 11 May 2011 15:26:32 -0400 Subject: [PATCH 4/7] Rework WebGUI::Test::getPage2 to be a wrapper around WebGUI::Test::Mechanize; this is still just a crutch for converting tests, though really, it's enough shorter that it probably should live on. getPage should be deprecated and replaced with getPage2 which should then be renamed. Joy. Anyway, WebGUI::Test::Mechanize had a bit of chicken-and-egg going on with not being able to modify things in its session until after a request with a valid session cookie was made. It's now more forgiving. Reworked t/Asset/AssetExportHtml.t slightly to use getPage2 as it currently stands. --- lib/WebGUI/Test.pm | 50 ++++++++++++++---------------------- lib/WebGUI/Test/Mechanize.pm | 11 ++++++-- t/Asset/AssetExportHtml.t | 14 +++++----- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/lib/WebGUI/Test.pm b/lib/WebGUI/Test.pm index 2eb15b6ed..b708f39de 100644 --- a/lib/WebGUI/Test.pm +++ b/lib/WebGUI/Test.pm @@ -45,12 +45,8 @@ use Scope::Guard; use WebGUI::Paths -inc; use namespace::clean; use WebGUI::User; - -use Plack::Test; -use Plack::Util; +use WebGUI::Test::Mechanize; use HTTP::Request::Common; -use WebGUI::GUID; - our @EXPORT = qw(cleanupGuard addToCleanup); our @EXPORT_OK = qw(session config collateral); @@ -440,12 +436,14 @@ sub getPage { =head2 getPage2 ( request|url [, opts] ) -Get the entire response from a page request using L. +Get the entire response from a page request using L. +This is a wrapper around L for the purpose of easing conversion of tests that use C. Accepts an L object as an argument, which cooked up auth info will be added to. An L will be constructed from a simple relative URL such as C if a string is passed instead. -Returns an L object on which you may call C<< decoded_content() >> to get the body content as a string. +Returns a string containing the body of the requested page. + C is a hash reference of options with keys outlined below. user => A user object to set for this request @@ -469,7 +467,6 @@ sub getPage2 { # precedence die "not supported" if exists $optionsRef->{args}; - die "not supported" if exists $optionsRef->{formParams}; die "not supported" if exists $optionsRef->{uploads}; my $session = $CLASS->session; @@ -478,48 +475,39 @@ sub getPage2 { my $oldUser = $session->user; my $oldRequest = $session->request; + my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file ); + # Set the appropriate user if ($optionsRef->{user}) { - $session->user({ user => $optionsRef->{user} }); + $mech->session->user({ user => $optionsRef->{user} }); } elsif ($optionsRef->{userId}) { - $session->user({ userId => $optionsRef->{userId} }); + $mech->session->user({ userId => $optionsRef->{userId} }); } $session->user->uncache; - # Fake up a logged in session - my $wgSession = WebGUI::GUID->generate; - $session->db->write(qq{ - replace into userSession (sessionId, expires, lastPageView, userId) - values (?, ?, ?, ?) - }, [ - $wgSession, scalar time + 60 * 20, scalar time, $session->user->userId, - ] ) or die; + $mech->session or die; # force a session to be created for the request + my $session_id = $mech->sessionId or die; - my $response; - - # Create a new request object, or fix up the one given to us + # Build or fix up a request object if( ! eval { $request->isa('HTTP::Request') } ) { if( $optionsRef->{formParams} ) { $request = HTTP::Request::Common::POST( "http://127.0.0.1/$request", [ %{ $optionsRef->{formParams} } ] ) or die; - } else { + } + else { $request = HTTP::Request->new( GET => "http://127.0.0.1/$request" ) or die; } - } - $request->header( 'Set-Cookie3' => qq{wgSession=$wgSession; path="/"; domain=127.0.0.1; path_spec; discard; version=0} ); + } + $request->header( 'Set-Cookie3' => qq{wgSession=$session_id; path="/"; domain=127.0.0.1; path_spec; discard; version=0} ); - my $app = Plack::Util::load_psgi( WebGUI::Paths->defaultPSGI ) or die; - - test_psgi $app, sub { - my $cb = shift; - $response = $cb->( $request ); - }; + $mech->request( $request ); # Restore the former user and request $session->user({ user => $oldUser }); $session->{_request} = $oldRequest; # dubious about this; if we're going to try to support requests inside of other requests, it should be tested and actually supported rather than just some optimistic arm waving done - return $response; + return $mech->response->decoded_content; + } #---------------------------------------------------------------------------- diff --git a/lib/WebGUI/Test/Mechanize.pm b/lib/WebGUI/Test/Mechanize.pm index 9330683e2..e6161d657 100644 --- a/lib/WebGUI/Test/Mechanize.pm +++ b/lib/WebGUI/Test/Mechanize.pm @@ -58,10 +58,15 @@ sub new { sub session { my $self = shift; + if( @_ ) { + $self->{_webgui_session} = shift; # take session as an arg + $self->{_webgui_sessionId} ||= $self->{_webgui_session}->getId; + } return $self->{_webgui_session} if $self->{_webgui_session}; - my $session = WebGUI::Session->open($self->{_webgui_config}, undef, $self->sessionId); + my $session = WebGUI::Session->open($self->{_webgui_config}, undef, $self->sessionId) or die; $self->{_webgui_session} = $session; + $self->{_webgui_sessionId} ||= $session->getId; # sessionId() sets it from return $session; } @@ -78,7 +83,9 @@ sub sessionId { } }); if (! $sessionId) { - die "Unable to find session cookie!"; + # die "Unable to find session cookie!"; + # when called from session() above, there is no session yet and no sessionId; that's okay + return; # empty list; make WebGUI::Session generate one for us } $self->{_webgui_sessionId} = $sessionId; return $sessionId; diff --git a/t/Asset/AssetExportHtml.t b/t/Asset/AssetExportHtml.t index 94914c6df..48ff437dc 100644 --- a/t/Asset/AssetExportHtml.t +++ b/t/Asset/AssetExportHtml.t @@ -392,12 +392,10 @@ is($@, '', "exportWriteFile works when creating exportPath"); ok(-e $parent->exportGetUrlAsPath->absolute->stringify, "exportWriteFile actually writes the file when creating exportPath"); # now make sure that it contains the correct content -eval { - $content = WebGUI::Test->getPage2( - $parent->get('url').'?func=exportHtml_view', - { user => WebGUI::User->new($session, 1) }, - )->decoded_content -}; +$content = WebGUI::Test->getPage2( + $parent->get('url').'?func=exportHtml_view', + { user => WebGUI::User->new($session, 1) }, +); is(scalar $parent->exportGetUrlAsPath->slurp, $content, "exportWriteFile puts the correct contents in exported parent"); @@ -449,7 +447,7 @@ is($@, '', "exportWriteFile works for first_child"); ok(-e $firstChild->exportGetUrlAsPath->absolute->stringify, "exportWriteFile actually writes the first_child file"); # verify it has the correct contents -eval { $content = WebGUI::Test->getPage2( $firstChild->get('url').'?func=exportHtml_view', )->decoded_content }; +eval { $content = WebGUI::Test->getPage2( $firstChild->get('url').'?func=exportHtml_view', ) }; is(scalar $firstChild->exportGetUrlAsPath->absolute->slurp, $content, "exportWriteFile puts the correct contents in exported first_child"); # and one more level. remove the export path to ensure directory creation keeps @@ -466,7 +464,7 @@ ok(-e $grandChild->exportGetUrlAsPath->absolute->stringify, "exportWriteFile act # finally, check its contents $session->style->sent(0); -eval { $content = WebGUI::Test->getPage2( $grandChild->get('url').'?func=exportHtml_view', )->decoded_content }; +eval { $content = WebGUI::Test->getPage2( $grandChild->get('url').'?func=exportHtml_view', ) }; is(scalar $grandChild->exportGetUrlAsPath->absolute->slurp, $content, "exportWriteFile puts correct content in exported grandchild"); # test different extensions From 57d2dbed56969aff99cc6eb1f582b78a915c33f9 Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Wed, 11 May 2011 16:17:54 -0400 Subject: [PATCH 5/7] WebGUI::Session::Http should go away (#11647) Move logic out of WebGUI::Session::HTTP and into WebGUI::Session::Response / ::Request; deprecate more functions; change references in core to use $session->response instead; fix tests that broke because of the change but not one that merely generate the deprecated warning because I want to know that the proxying of depricated methods is working. These can be changed later. --- lib/WebGUI.pm | 6 +- lib/WebGUI/Account.pm | 2 +- lib/WebGUI/AdminConsole.pm | 2 +- lib/WebGUI/Asset.pm | 28 +- lib/WebGUI/Asset/Event.pm | 6 +- lib/WebGUI/Asset/File.pm | 6 +- lib/WebGUI/Asset/File/GalleryFile.pm | 4 +- lib/WebGUI/Asset/File/GalleryFile/Photo.pm | 2 +- lib/WebGUI/Asset/File/ZipArchive.pm | 2 +- lib/WebGUI/Asset/MapPoint.pm | 2 +- lib/WebGUI/Asset/MatrixListing.pm | 4 +- lib/WebGUI/Asset/Post/Thread.pm | 28 +- lib/WebGUI/Asset/Redirect.pm | 4 +- lib/WebGUI/Asset/Shortcut.pm | 4 +- lib/WebGUI/Asset/Sku.pm | 4 +- lib/WebGUI/Asset/Sku/Ad.pm | 4 +- lib/WebGUI/Asset/Sku/Product.pm | 2 +- lib/WebGUI/Asset/Snippet.pm | 2 +- lib/WebGUI/Asset/Story.pm | 2 +- lib/WebGUI/Asset/Template.pm | 2 +- lib/WebGUI/Asset/WikiPage.pm | 6 +- lib/WebGUI/Asset/Wobject.pm | 4 +- lib/WebGUI/Asset/Wobject/Article.pm | 2 +- lib/WebGUI/Asset/Wobject/Collaboration.pm | 2 +- lib/WebGUI/Asset/Wobject/Dashboard.pm | 4 +- lib/WebGUI/Asset/Wobject/DataForm.pm | 4 +- lib/WebGUI/Asset/Wobject/Folder.pm | 2 +- lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 4 +- lib/WebGUI/Asset/Wobject/HttpProxy.pm | 2 +- lib/WebGUI/Asset/Wobject/Layout.pm | 4 +- lib/WebGUI/Asset/Wobject/Matrix.pm | 2 +- lib/WebGUI/Asset/Wobject/MessageBoard.pm | 2 +- lib/WebGUI/Asset/Wobject/MultiSearch.pm | 2 +- lib/WebGUI/Asset/Wobject/Navigation.pm | 2 +- lib/WebGUI/Asset/Wobject/SQLReport.pm | 4 +- lib/WebGUI/Asset/Wobject/SyndicatedContent.pm | 2 +- lib/WebGUI/AssetPackage.pm | 6 +- lib/WebGUI/AssetVersioning.pm | 2 +- lib/WebGUI/Auth.pm | 14 +- lib/WebGUI/Auth/Facebook.pm | 2 +- lib/WebGUI/Auth/Twitter.pm | 2 +- lib/WebGUI/Content/Asset.pm | 6 +- lib/WebGUI/Content/Maintenance.pm | 2 +- lib/WebGUI/Fork.pm | 2 +- lib/WebGUI/Form/Asset.pm | 2 +- lib/WebGUI/Form/Attachments.pm | 2 +- lib/WebGUI/Form/HTMLArea.pm | 18 +- lib/WebGUI/Operation/AdSpace.pm | 2 +- lib/WebGUI/Operation/Admin.pm | 4 +- lib/WebGUI/Operation/Auth.pm | 2 +- lib/WebGUI/Operation/Cron.pm | 2 +- lib/WebGUI/Operation/LDAPLink.pm | 2 +- lib/WebGUI/Operation/Spectre.pm | 6 +- lib/WebGUI/Operation/User.pm | 2 +- lib/WebGUI/Operation/VersionTag.pm | 2 +- lib/WebGUI/Operation/Workflow.pm | 2 +- lib/WebGUI/PassiveAnalytics/Flow.pm | 2 +- lib/WebGUI/ProgressBar.pm | 4 +- lib/WebGUI/Role/Asset/RssFeed.pm | 2 +- lib/WebGUI/Session.pm | 1 + lib/WebGUI/Session/Http.pm | 326 +++++++----------- lib/WebGUI/Session/Response.pm | 309 +++++++++++++++++ lib/WebGUI/Session/Style.pm | 4 +- lib/WebGUI/Session/Url.pm | 4 +- lib/WebGUI/Shop/PayDriver.pm | 2 +- lib/WebGUI/Shop/PayDriver/Ogone.pm | 6 +- .../Shop/PayDriver/PayPal/ExpressCheckout.pm | 2 +- lib/WebGUI/Shop/ShipDriver.pm | 2 +- lib/WebGUI/Shop/TaxDriver/Generic.pm | 2 +- lib/WebGUI/VersionTag.pm | 2 +- lib/WebGUI/Wizard.pm | 2 +- lib/WebGUI/Wizard/HomePage.pm | 2 +- lib/WebGUI/Wizard/Setup.pm | 10 +- sbin/testEnvironment.pl | 1 + t/Session/Http.t | 5 + t/Session/Style.t | 5 +- 76 files changed, 581 insertions(+), 358 deletions(-) diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index e6fcf2bc1..a175ea999 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -175,7 +175,7 @@ sub handle { # A WebGUI::Asset::Template object means we should process it if ( defined $output && blessed $output && $output->isa( 'WebGUI::Asset::Template' ) ) { - $session->http->sendHeader; + $session->response->sendHeader; $session->output->print( $output->process ); return; } @@ -187,7 +187,7 @@ sub handle { # other non-empty output should be used as the response body elsif (defined $output && $output ne "") { # Auto-set the headers - $session->http->sendHeader; + $session->response->sendHeader; # Use contentHandler's return value as the output $session->output->print($output); @@ -195,7 +195,7 @@ sub handle { } # Keep processing for success codes elsif ($session->response->status < 200 || $session->response->status > 299) { - $session->http->sendHeader; + $session->response->sendHeader; return; } } diff --git a/lib/WebGUI/Account.pm b/lib/WebGUI/Account.pm index bcac41a2f..1ddd432fd 100644 --- a/lib/WebGUI/Account.pm +++ b/lib/WebGUI/Account.pm @@ -287,7 +287,7 @@ sub displayContent { return $output if($noStyle); #Wrap the layout in the user style - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); return $session->style->process($output,$self->getStyleTemplateId); } diff --git a/lib/WebGUI/AdminConsole.pm b/lib/WebGUI/AdminConsole.pm index c5ff71049..2f1be5e29 100644 --- a/lib/WebGUI/AdminConsole.pm +++ b/lib/WebGUI/AdminConsole.pm @@ -255,7 +255,7 @@ A string that defaults to _function's title. sub render { my $self = shift; my $session = $self->session; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my %var; $var{"application_loop"} = $self->getAdminFunction; $var{"application.workarea"} = shift; diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 03c728c20..6913785aa 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -653,11 +653,11 @@ sub checkView { my $self = shift; return $self->session->privilege->noAccess() unless $self->canView; my $session = $self->session; - my ($conf, $http) = $self->session->quick(qw(config http)); + my ($conf, $response) = $self->session->quick(qw(config response)); if ($conf->get("sslEnabled") && $self->get("encryptPage") && ! $self->session->request->secure) { # getUrl already changes url to https if 'encryptPage' - $http->setRedirect($self->getUrl); - $http->sendHeader; + $response->setRedirect($self->getUrl); + $response->sendHeader; return "chunked"; } elsif ($session->isAdminOn && $self->get("state") =~ /^trash/) { # show em trash @@ -665,8 +665,8 @@ sub checkView { if ($self->session->form->process('revision')) { $queryFrag .= ";revision=".$self->session->form->process('revision'); } - $http->setRedirect($self->getUrl($queryFrag)); - $http->sendHeader; + $response->setRedirect($self->getUrl($queryFrag)); + $response->sendHeader; return "chunked"; } elsif ($session->isAdminOn && $self->get("state") =~ /^clipboard/) { # show em clipboard @@ -674,8 +674,8 @@ sub checkView { if ($self->session->form->process('revision')) { $queryFrag .= ";revision=".$self->session->form->process('revision'); } - $http->setRedirect($self->getUrl($queryFrag)); - $http->sendHeader; + $response->setRedirect($self->getUrl($queryFrag)); + $response->sendHeader; return "chunked"; } elsif ($self->get("state") ne "published") { # tell em it doesn't exist anymore @@ -949,7 +949,7 @@ sub forkWithStatusPage { proceed => $args->{redirect} || '', } ); - $session->http->setRedirect( $self->getUrl($pairs) ); + $session->response->setRedirect( $self->getUrl($pairs) ); return 'redirect'; } ## end sub forkWithStatusPage @@ -2199,23 +2199,23 @@ sub proceed { return $session->asset->www_manageAssets; } elsif ($proceed eq "viewParent") { - $session->http->setRedirect( $self->getParent->getUrl ); + $session->response->setRedirect( $self->getParent->getUrl ); return "redirect"; } elsif ($proceed eq "editParent") { - $session->http->setRedirect( $self->getParent->getUrl('func=edit') ); + $session->response->setRedirect( $self->getParent->getUrl('func=edit') ); return "redirect"; } elsif ($proceed eq "goBackToPage" && $session->form->process('returnUrl')) { - $session->http->setRedirect($session->form->process("returnUrl")); + $session->response->setRedirect($session->form->process("returnUrl")); return "redirect"; } elsif ($proceed ne "") { - $session->http->setRedirect( $self->getUrl( 'func=' . $proceed ) ); + $session->response->setRedirect( $self->getUrl( 'func=' . $proceed ) ); return "redirect"; } - $session->http->setRedirect( $self->getUrl ); + $session->response->setRedirect( $self->getUrl ); return "redirect"; } @@ -2936,7 +2936,7 @@ sub www_view { # don't allow viewing of the root asset if ($self->getId eq "PBasset000000000000001") { - $self->session->http->setRedirect($self->getDefault($self->session)->getUrl); + $self->session->response->setRedirect($self->getDefault($self->session)->getUrl); return undef; } diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 2044e3851..3c00ecf78 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -2340,7 +2340,7 @@ ENDJS ### Show the processed template - $session->http->sendHeader; + $session->response->sendHeader; my $style = $self->getParent->processStyle($self->getSeparator); my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head, 1); @@ -2376,8 +2376,8 @@ sub www_view { return $self->session->privilege->noAccess() unless $self->canView; my $check = $self->checkView; return $check if (defined $check); - $self->session->http->setCacheControl($self->getParent->visitorCacheTimeout) if ($self->session->user->isVisitor); - $self->session->http->sendHeader; + $self->session->response->setCacheControl($self->getParent->visitorCacheTimeout) if ($self->session->user->isVisitor); + $self->session->response->sendHeader; $self->prepareView; my $style = $self->getParent->processStyle($self->getSeparator); my ($head, $foot) = split($self->getSeparator,$style); diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index e10b35891..f1b49f8b1 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -619,9 +619,9 @@ sub www_view { return sprintf($i18n->get("file not found"), $self->getUrl()); } - $session->http->setRedirect($self->getFileUrl) unless $session->config->get('enableStreamingUploads'); - $session->http->setStreamedFile($self->getStorageLocation->getPath($self->filename)); - $session->http->sendHeader; + $session->response->setRedirect($self->getFileUrl) unless $session->config->get('enableStreamingUploads'); + $session->response->setStreamedFile($self->getStorageLocation->getPath($self->filename)); + $session->response->sendHeader; return 'chunked'; } diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index 787676db5..5feb3a261 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -1154,8 +1154,8 @@ sub www_view { # Add to views $self->update({ views => $self->views + 1 }); - $self->session->http->setLastModified($self->getContentLastModified); - $self->session->http->sendHeader; + $self->session->response->setLastModified($self->getContentLastModified); + $self->session->response->sendHeader; $self->prepareView; my $style = $self->processStyle($self->getSeparator); my ($head, $foot) = split($self->getSeparator,$style); diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index aebaf5c4c..cffd05072 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -548,7 +548,7 @@ sub www_download { my $storage = $self->getStorageLocation; $self->session->response->content_type( "image/jpeg" ); - $self->session->http->setLastModified( $self->getContentLastModified ); + $self->session->response->setLastModified( $self->getContentLastModified ); my $resolution = $self->session->form->get("resolution"); if ($resolution) { diff --git a/lib/WebGUI/Asset/File/ZipArchive.pm b/lib/WebGUI/Asset/File/ZipArchive.pm index 2a27467d5..6f8a5a9c0 100644 --- a/lib/WebGUI/Asset/File/ZipArchive.pm +++ b/lib/WebGUI/Asset/File/ZipArchive.pm @@ -270,7 +270,7 @@ sub www_view { if ($self->session->isAdminOn) { return $self->session->asset($self->getContainer)->www_view; } - $self->session->http->setRedirect($self->getFileUrl($self->showPage)); + $self->session->response->setRedirect($self->getFileUrl($self->showPage)); return "1"; } diff --git a/lib/WebGUI/Asset/MapPoint.pm b/lib/WebGUI/Asset/MapPoint.pm index 752b7ae65..c9a7d13d1 100644 --- a/lib/WebGUI/Asset/MapPoint.pm +++ b/lib/WebGUI/Asset/MapPoint.pm @@ -383,7 +383,7 @@ so that this point is automatically shown. sub www_view { my $self = shift; - $self->session->http->setRedirect( + $self->session->response->setRedirect( $self->getParent->getUrl('focusOn=' . $self->getId ) ); return "redirect"; diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index e67e5967c..93cad8440 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -785,10 +785,10 @@ sub www_click { $self->incrementCounter('clicks'); if ($session->form->process("manufacturer")) { - $session->http->setRedirect( $self->get('manufacturerURL') ); + $session->response->setRedirect( $self->get('manufacturerURL') ); } else { - $session->http->setRedirect( $self->get('productURL') ); + $session->response->setRedirect( $self->get('productURL') ); } return undef; } diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index 57d329378..df0381273 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -1424,20 +1424,20 @@ Renders self->view based upon current style, subject to timeouts. Returns Privil =cut sub www_view { - my $self = shift; - my $currentPost = shift; - return $self->session->privilege->noAccess() unless $self->canView; - my $check = $self->checkView; - return $check if (defined $check); - $self->session->http->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor); - $self->session->http->sendHeader; - $self->prepareView; - my $style = $self->getParent->processStyle($self->getSeparator); - my ($head, $foot) = split($self->getSeparator,$style); - $self->session->output->print($head,1); - $self->session->output->print($self->view($currentPost)); - $self->session->output->print($foot,1); - return "chunked"; + my $self = shift; + my $currentPost = shift; + return $self->session->privilege->noAccess() unless $self->canView; + my $check = $self->checkView; + return $check if (defined $check); + $self->session->response->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor); + $self->session->response->sendHeader; + $self->prepareView; + my $style = $self->getParent->processStyle($self->getSeparator); + my ($head, $foot) = split($self->getSeparator,$style); + $self->session->output->print($head,1); + $self->session->output->print($self->view($currentPost)); + $self->session->output->print($foot,1); + return "chunked"; } diff --git a/lib/WebGUI/Asset/Redirect.pm b/lib/WebGUI/Asset/Redirect.pm index d250aed76..e4667d561 100644 --- a/lib/WebGUI/Asset/Redirect.pm +++ b/lib/WebGUI/Asset/Redirect.pm @@ -85,7 +85,7 @@ sub exportHtml_view { my $url = $self->redirectUrl; WebGUI::Macro::process($self->session, \$url); return '' if ($url eq $self->url); - $self->session->http->setRedirect($url); + $self->session->response->setRedirect($url); return $self->session->style->process('', 'PBtmpl0000000000000060'); } @@ -130,7 +130,7 @@ sub www_view { ',$i18n->get("assetName")); } unless ($url eq $self->url) { - $self->session->http->setRedirect($url,$self->redirectType); + $self->session->response->setRedirect($url,$self->redirectType); return undef; } return $i18n->get('self_referential'); diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index e8af8cf52..282d4b83a 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -1255,8 +1255,8 @@ sub www_view { $shortcut->purgeCache(); if ($shortcut->isa('WebGUI::Asset::Wobject')) { - $self->session->http->setLastModified($self->getContentLastModified); - $self->session->http->sendHeader; + $self->session->response->setLastModified($self->getContentLastModified); + $self->session->response->sendHeader; ##Tell processStyle not to set the h my $style = $shortcut->processStyle($shortcut->getSeparator, { noHeadTags => 1 }); my ($head, $foot) = split($shortcut->getSeparator,$style); diff --git a/lib/WebGUI/Asset/Sku.pm b/lib/WebGUI/Asset/Sku.pm index 64e9924a4..675dcaa59 100644 --- a/lib/WebGUI/Asset/Sku.pm +++ b/lib/WebGUI/Asset/Sku.pm @@ -647,8 +647,8 @@ sub www_view { my $self = shift; my $check = $self->checkView; return $check if (defined $check); - $self->session->http->setLastModified($self->getContentLastModified); - $self->session->http->sendHeader; + $self->session->response->setLastModified($self->getContentLastModified); + $self->session->response->sendHeader; $self->prepareView; my $style = $self->processStyle($self->getSeparator); my ($head, $foot) = split($self->getSeparator,$style); diff --git a/lib/WebGUI/Asset/Sku/Ad.pm b/lib/WebGUI/Asset/Sku/Ad.pm index b59555eeb..b29098678 100644 --- a/lib/WebGUI/Asset/Sku/Ad.pm +++ b/lib/WebGUI/Asset/Sku/Ad.pm @@ -584,8 +584,8 @@ sub www_manage { my $self = shift; my $check = $self->checkView; return $check if (defined $check); - $self->session->http->setLastModified($self->getContentLastModified); - $self->session->http->sendHeader; + $self->session->response->setLastModified($self->getContentLastModified); + $self->session->response->sendHeader; $self->prepareView($self->manageTemplate); my $style = $self->processStyle($self->getSeparator); my ($head, $foot) = split($self->getSeparator,$style); diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 81d6ff039..6eb45722c 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -1896,7 +1896,7 @@ Extend the base method to handle caching. override www_view => sub { my $self = shift; - $self->session->http->setCacheControl($self->cacheTimeout); + $self->session->response->setCacheControl($self->cacheTimeout); super(); }; diff --git a/lib/WebGUI/Asset/Snippet.pm b/lib/WebGUI/Asset/Snippet.pm index 9dc81cda4..5ad88a16b 100644 --- a/lib/WebGUI/Asset/Snippet.pm +++ b/lib/WebGUI/Asset/Snippet.pm @@ -275,7 +275,7 @@ sub www_view { return $self->session->privilege->insufficient() unless $self->canView; my $mimeType=$self->mimeType; $self->session->response->content_type($mimeType || 'text/html'); - $self->session->http->setCacheControl($self->cacheTimeout); + $self->session->response->setCacheControl($self->cacheTimeout); my $output = $self->view(1); if (!defined $output) { $output = 'empty'; diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index dc6ad37ed..49735bc5b 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -918,7 +918,7 @@ the Story Archive that contains them. sub www_view { my $self = shift; return $self->session->privilege->noAccess unless $self->canView; - $self->session->http->sendHeader; + $self->session->response->sendHeader; $self->prepareView; return $self->getArchive->processStyle($self->view); } diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 092b4b8e4..b1e0e1c4c 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -847,7 +847,7 @@ the user back to the site. sub www_goBackToPage { my $self = shift; - $self->session->http->setRedirect($self->session->form->get("returnUrl")) if ($self->session->form->get("returnUrl")); + $self->session->response->setRedirect($self->session->form->get("returnUrl")) if ($self->session->form->get("returnUrl")); return undef; } diff --git a/lib/WebGUI/Asset/WikiPage.pm b/lib/WebGUI/Asset/WikiPage.pm index bc94972c9..582b83dc2 100644 --- a/lib/WebGUI/Asset/WikiPage.pm +++ b/lib/WebGUI/Asset/WikiPage.pm @@ -548,7 +548,7 @@ sub www_purgeRevision { $asset->purgeRevision; if ($session->form->process("proceed") eq "manageRevisionsInTag") { my $working = (defined $self) ? $self : $parent; - $session->http->setRedirect($working->getUrl("op=manageRevisionsInTag")); + $session->response->setRedirect($working->getUrl("op=manageRevisionsInTag")); return undef; } unless (defined $self) { @@ -601,9 +601,9 @@ sub www_view { return $self->session->privilege->noAccess unless $self->canView; $self->update({ views => $self->views+1 }); # TODO: This should probably exist, as the CS has one. -# $self->session->http->setCacheControl($self->getWiki->get('visitorCacheTimeout')) +# $self->session->response->setCacheControl($self->getWiki->get('visitorCacheTimeout')) # if ($self->session->user->isVisitor); - $self->session->http->sendHeader; + $self->session->response->sendHeader; $self->prepareView; return $self->getWiki->processStyle($self->view); } diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 389144e5a..e64b4b050 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -505,8 +505,8 @@ sub www_view { my $self = shift; my $check = $self->checkView; return $check if (defined $check); - $self->session->http->setLastModified($self->getContentLastModified); - $self->session->http->sendHeader; + $self->session->response->setLastModified($self->getContentLastModified); + $self->session->response->sendHeader; ##Have to dupe this code here because Wobject does not call SUPER. $self->prepareView; my $style = $self->processStyle($self->getSeparator, { noHeadTags => 1 }); diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm index b963285c6..f19d29692 100644 --- a/lib/WebGUI/Asset/Wobject/Article.pm +++ b/lib/WebGUI/Asset/Wobject/Article.pm @@ -433,7 +433,7 @@ See WebGUI::Asset::Wobject::www_view() for details. override www_view => sub { my $self = shift; - $self->session->http->setCacheControl($self->cacheTimeout); + $self->session->response->setCacheControl($self->cacheTimeout); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 8c1ce322b..87b200036 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -1776,7 +1776,7 @@ Extend the base method to handle the visitor cache timeout. sub www_view { my $self = shift; my $disableCache = ($self->session->form->process("sortBy") ne ""); - $self->session->http->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor && !$disableCache); + $self->session->response->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor && !$disableCache); return $self->next::method(@_); } diff --git a/lib/WebGUI/Asset/Wobject/Dashboard.pm b/lib/WebGUI/Asset/Wobject/Dashboard.pm index e6438308e..17ed193d6 100644 --- a/lib/WebGUI/Asset/Wobject/Dashboard.pm +++ b/lib/WebGUI/Asset/Wobject/Dashboard.pm @@ -460,10 +460,10 @@ sub www_view { if ($self->state eq "published") { # no privileges, make em log in return $self->session->privilege->noAccess(); } elsif ($self->session->isAdminOn && $self->state =~ /^trash/) { # show em trash - $self->session->http->setRedirect($self->getUrl("func=manageTrash")); + $self->session->response->setRedirect($self->getUrl("func=manageTrash")); return undef; } elsif ($self->session->isAdminOn && $self->state =~ /^clipboard/) { # show em clipboard - $self->session->http->setRedirect($self->getUrl("func=manageClipboard")); + $self->session->response->setRedirect($self->getUrl("func=manageClipboard")); return undef; } else { # tell em it doesn't exist anymore $self->session->response->status(410); diff --git a/lib/WebGUI/Asset/Wobject/DataForm.pm b/lib/WebGUI/Asset/Wobject/DataForm.pm index 2c2bb3007..8a2ad4564 100644 --- a/lib/WebGUI/Asset/Wobject/DataForm.pm +++ b/lib/WebGUI/Asset/Wobject/DataForm.pm @@ -1339,7 +1339,7 @@ sub viewForm { } $var = $passedVars || $self->getRecordTemplateVars($var, $entry); if ($self->hasCaptcha) { - $self->session->http->setCacheControl('none'); + $self->session->response->setCacheControl('none'); } return $self->processTemplate($var, undef, $self->{_viewFormTemplate}); } @@ -1889,7 +1889,7 @@ sub www_exportTab { $session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$self->url.'.tab"'); $session->response->content_type('text/plain'); - $session->http->sendHeader; + $session->response->sendHeader; $session->output->print($tsv->string, 1); my $entryIter = $self->entryClass->iterateAll($self); diff --git a/lib/WebGUI/Asset/Wobject/Folder.pm b/lib/WebGUI/Asset/Wobject/Folder.pm index 98ff91d1e..98b3f91ab 100644 --- a/lib/WebGUI/Asset/Wobject/Folder.pm +++ b/lib/WebGUI/Asset/Wobject/Folder.pm @@ -282,7 +282,7 @@ See WebGUI::Asset::Wobject::www_view() for details. override www_view => sub { my $self = shift; - $self->session->http->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor); + $self->session->response->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index 71eb888d7..54112ae95 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -837,8 +837,8 @@ sub sendChunkedContent { my $session = $self->session; - $session->http->setLastModified($self->getContentLastModified); - $session->http->sendHeader; + $session->response->setLastModified($self->getContentLastModified); + $session->response->sendHeader; my $style = $self->processStyle($self->getSeparator); my ($head, $foot) = split($self->getSeparator,$style); $session->output->print($head, 1); diff --git a/lib/WebGUI/Asset/Wobject/HttpProxy.pm b/lib/WebGUI/Asset/Wobject/HttpProxy.pm index 0c234f200..591474d83 100644 --- a/lib/WebGUI/Asset/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Asset/Wobject/HttpProxy.pm @@ -497,7 +497,7 @@ sub www_view { if ($self->session->response->content_type ne "text/html") { return $output; } else { - $self->session->http->sendHeader; + $self->session->response->sendHeader; my $style = $self->processStyle($self->getSeparator, { noHeadTags => 1 }); my ($head, $foot) = split($self->getSeparator,$style); $self->session->output->print($head); diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index 27104a286..2ff518a4e 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -396,8 +396,8 @@ override www_view => sub { my $ad = $adSpace->displayImpression if (defined $adSpace); $out =~ s/\Q$code/$ad/ges; } - $session->http->setLastModified($self->getContentLastModified); - $session->http->sendHeader; + $session->response->setLastModified($self->getContentLastModified); + $session->response->sendHeader; $session->output->print($out, 1); return "chunked"; } diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index bd10ce50b..55a696881 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -1080,7 +1080,7 @@ sub www_exportAttributes { $session->response->header( 'Content-Disposition' => qq{attachment; filename="export_matrix_attributes.csv"}); $session->response->content_type('application/octet-stream'); - $self->session->http->sendHeader; + $self->session->response->sendHeader; return $output; } diff --git a/lib/WebGUI/Asset/Wobject/MessageBoard.pm b/lib/WebGUI/Asset/Wobject/MessageBoard.pm index 6a1e42385..ddb9861cb 100644 --- a/lib/WebGUI/Asset/Wobject/MessageBoard.pm +++ b/lib/WebGUI/Asset/Wobject/MessageBoard.pm @@ -178,7 +178,7 @@ See WebGUI::Asset::Wobject::www_view() for details. override www_view => sub { my $self = shift; - $self->session->http->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor); + $self->session->response->setCacheControl($self->visitorCacheTimeout) if ($self->session->user->isVisitor); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/MultiSearch.pm b/lib/WebGUI/Asset/Wobject/MultiSearch.pm index 217f83fb2..807cc855f 100644 --- a/lib/WebGUI/Asset/Wobject/MultiSearch.pm +++ b/lib/WebGUI/Asset/Wobject/MultiSearch.pm @@ -128,7 +128,7 @@ See WebGUI::Asset::Wobject::www_view() for details. override www_view => sub { my $self = shift; - $self->session->http->setCacheControl($self->cacheTimeout); + $self->session->response->setCacheControl($self->cacheTimeout); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/Navigation.pm b/lib/WebGUI/Asset/Wobject/Navigation.pm index fb83edbb9..52e9d95d5 100644 --- a/lib/WebGUI/Asset/Wobject/Navigation.pm +++ b/lib/WebGUI/Asset/Wobject/Navigation.pm @@ -504,7 +504,7 @@ Do a redirect to the form parameter returnUrl if it exists. sub www_goBackToPage { my $self = shift; - $self->session->http->setRedirect($self->session->form->process("returnUrl")) if ($self->session->form->process("returnUrl")); + $self->session->response->setRedirect($self->session->form->process("returnUrl")) if ($self->session->form->process("returnUrl")); return undef; } diff --git a/lib/WebGUI/Asset/Wobject/SQLReport.pm b/lib/WebGUI/Asset/Wobject/SQLReport.pm index b93a64e89..a7783a958 100644 --- a/lib/WebGUI/Asset/Wobject/SQLReport.pm +++ b/lib/WebGUI/Asset/Wobject/SQLReport.pm @@ -704,7 +704,7 @@ sub www_download { $self->downloadType eq 'csv' ? "application/octet-stream" : $self->downloadMimeType ); - $self->session->http->sendHeader; + $self->session->response->sendHeader; return $self->download; @@ -722,7 +722,7 @@ See WebGUI::Asset::Wobject::www_view() for details. override www_view => sub { my $self = shift; - $self->session->http->setCacheControl($self->cacheTimeout); + $self->session->response->setCacheControl($self->cacheTimeout); super(); }; diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index 4c2692a7c..a4e47a850 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -390,7 +390,7 @@ See WebGUI::Asset::Wobject::www_view() for details. override www_view => sub { my $self = shift; - $self->session->http->setCacheControl($self->cacheTimeout); + $self->session->response->setCacheControl($self->cacheTimeout); super(); }; diff --git a/lib/WebGUI/AssetPackage.pm b/lib/WebGUI/AssetPackage.pm index 763247324..c88c131cc 100644 --- a/lib/WebGUI/AssetPackage.pm +++ b/lib/WebGUI/AssetPackage.pm @@ -356,9 +356,9 @@ sub www_deployPackage { return undef; }; if ($session->form->param("proceed") eq "manageAssets") { - $session->http->setRedirect($self->getManagerUrl); + $session->response->setRedirect($self->getManagerUrl); } else { - $session->http->setRedirect($self->getUrl()); + $session->response->setRedirect($self->getUrl()); } return undef; } @@ -376,7 +376,7 @@ sub www_exportPackage { return $self->session->privilege->insufficient() unless ($self->canEdit); my $storage = $self->exportPackage; my $filename = $storage->getFiles->[0]; - $self->session->http->setRedirect($storage->getUrl($storage->getFiles->[0])); + $self->session->response->setRedirect($storage->getUrl($storage->getFiles->[0])); return "redirect"; } diff --git a/lib/WebGUI/AssetVersioning.pm b/lib/WebGUI/AssetVersioning.pm index 0d08bc0e7..fd8ff4c6e 100644 --- a/lib/WebGUI/AssetVersioning.pm +++ b/lib/WebGUI/AssetVersioning.pm @@ -615,7 +615,7 @@ sub www_purgeRevision { $asset->purgeRevision; if ($session->form->process("proceed") eq "manageRevisionsInTag") { my $working = (defined $self) ? $self : $parent; - $session->http->setRedirect($working->getUrl("op=manageRevisionsInTag")); + $session->response->setRedirect($working->getUrl("op=manageRevisionsInTag")); return undef; } unless (defined $self) { diff --git a/lib/WebGUI/Auth.pm b/lib/WebGUI/Auth.pm index b85b97e36..2512a00e7 100644 --- a/lib/WebGUI/Auth.pm +++ b/lib/WebGUI/Auth.pm @@ -966,12 +966,12 @@ sub www_createAccountSave { return $self->showMessageOnLogin; } elsif ($self->session->form->get('returnUrl')) { - $self->session->http->setRedirect( $self->session->form->get('returnUrl') ); + $self->session->response->setRedirect( $self->session->form->get('returnUrl') ); $self->session->scratch->delete("redirectAfterLogin"); } elsif ($self->session->scratch->get("redirectAfterLogin")) { my $url = $self->session->scratch->delete("redirectAfterLogin"); - $self->session->http->setRedirect($url); + $self->session->response->setRedirect($url); return undef; } else { @@ -1178,7 +1178,7 @@ sub www_login { if ($self->session->setting->get('encryptLogin')) { my $currentUrl = $self->session->url->page(undef,1); $currentUrl =~ s/^https:/http:/; - $self->session->http->setRedirect($currentUrl); + $self->session->response->setRedirect($currentUrl); } # Run on login @@ -1198,14 +1198,14 @@ sub www_login { return $self->showMessageOnLogin; } elsif ( $self->session->form->get('returnUrl') ) { - $self->session->http->setRedirect( $self->session->form->get('returnUrl') ); + $self->session->response->setRedirect( $self->session->form->get('returnUrl') ); $self->session->scratch->delete("redirectAfterLogin"); } elsif ( my $url = $self->session->scratch->delete("redirectAfterLogin") ) { - $self->session->http->setRedirect($url); + $self->session->response->setRedirect($url); } elsif ( $self->session->setting->get("redirectAfterLoginUrl") ) { - $self->session->http->setRedirect($self->session->setting->get("redirectAfterLoginUrl")); + $self->session->response->setRedirect($self->session->setting->get("redirectAfterLoginUrl")); $self->session->scratch->delete("redirectAfterLogin"); } @@ -1242,7 +1242,7 @@ sub www_logout { } # Do not allow caching of the logout page (to ensure the page gets requested) - $self->session->http->setCacheControl( "none" ); + $self->session->response->setCacheControl( "none" ); return undef; } diff --git a/lib/WebGUI/Auth/Facebook.pm b/lib/WebGUI/Auth/Facebook.pm index 427411225..98001c0c5 100644 --- a/lib/WebGUI/Auth/Facebook.pm +++ b/lib/WebGUI/Auth/Facebook.pm @@ -185,7 +185,7 @@ sub www_login { ->extend_permissions(qw(email)) ->uri_as_string; - $session->http->setRedirect($auth_url); + $session->response->setRedirect($auth_url); return "redirect"; } diff --git a/lib/WebGUI/Auth/Twitter.pm b/lib/WebGUI/Auth/Twitter.pm index dec1a7e9f..f11690d80 100644 --- a/lib/WebGUI/Auth/Twitter.pm +++ b/lib/WebGUI/Auth/Twitter.pm @@ -187,7 +187,7 @@ sub www_login { $scratch->set( 'AuthTwitterToken', $nt->request_token ); $scratch->set( 'AuthTwitterTokenSecret', $nt->request_token_secret ); - $session->http->setRedirect($auth_url); + $session->response->setRedirect($auth_url); return "redirect"; } diff --git a/lib/WebGUI/Content/Asset.pm b/lib/WebGUI/Content/Asset.pm index 8dae8c85b..f1d4929a4 100644 --- a/lib/WebGUI/Content/Asset.pm +++ b/lib/WebGUI/Content/Asset.pm @@ -71,7 +71,7 @@ sub dispatch { if ($session->user->isVisitor && !$session->request->ifModifiedSince($asset->getContentLastModified, $session->setting->get('maxCacheTimeout'))) { $session->response->status("304"); - $session->http->sendHeader; + $session->response->sendHeader; return "chunked"; } @@ -166,7 +166,7 @@ The content handler for this package. sub handler { my ($session) = @_; - my ($log, $http, $asset, $request, $config) = $session->quick(qw(errorHandler http asset request config)); + my ($log, $asset, $request, $config) = $session->quick(qw(errorHandler asset request config)); my $output = ""; if (my $perfLog = $log->performanceLogger) { #show performance indicators if required my $t = [Time::HiRes::gettimeofday()]; @@ -177,7 +177,7 @@ sub handler { $output = dispatch($session, getRequestedAssetUrl($session)); } - my $filename = $http->getStreamedFile(); + my $filename = $session->response->getStreamedFile(); if ((defined $filename) && ($config->get("enableStreamingUploads") eq "1")) { my $ct = guess_media_type($filename); my $oldContentType = $request->content_type($ct); diff --git a/lib/WebGUI/Content/Maintenance.pm b/lib/WebGUI/Content/Maintenance.pm index 3e242f41a..a0cfbd046 100644 --- a/lib/WebGUI/Content/Maintenance.pm +++ b/lib/WebGUI/Content/Maintenance.pm @@ -47,7 +47,7 @@ The content handler for this package. sub handler { my $session = shift; if ($session->setting->get("specialState") eq "upgrading") { - $session->http->sendHeader; + $session->response->sendHeader; open my $fh, '<', $session->config->get('maintenancePage'); my $output = do { local $/; <$fh> }; close $fh; diff --git a/lib/WebGUI/Fork.pm b/lib/WebGUI/Fork.pm index e9b02e704..689b9c704 100644 --- a/lib/WebGUI/Fork.pm +++ b/lib/WebGUI/Fork.pm @@ -43,7 +43,7 @@ status of. ); # See WebGUI::Operation::Fork my $pairs = $process->contentPairs('DoWork'); - $session->http->setRedirect($self->getUrl($pairs)); + $session->response->setRedirect($self->getUrl($pairs)); return 'redirect'; } diff --git a/lib/WebGUI/Form/Asset.pm b/lib/WebGUI/Form/Asset.pm index bb3af2a88..6fc9f808a 100644 --- a/lib/WebGUI/Form/Asset.pm +++ b/lib/WebGUI/Form/Asset.pm @@ -181,7 +181,7 @@ form variable C. A crumb trail is provided for navigation. sub www_assetTree { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); my @crumb; my $ancestorIter = $base->getLineageIterator(["self","ancestors"]); diff --git a/lib/WebGUI/Form/Attachments.pm b/lib/WebGUI/Form/Attachments.pm index f4396120e..5f975b1dd 100644 --- a/lib/WebGUI/Form/Attachments.pm +++ b/lib/WebGUI/Form/Attachments.pm @@ -213,7 +213,7 @@ sub www_show { else { @assetIds = $session->form->param("attachments"); } - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); $style->setScript($url->extras("/AttachmentsControl/AttachmentsControl.js")); $style->setCss($url->extras("/AttachmentsControl/AttachmentsControl.css")); my $uploadControl = ''; diff --git a/lib/WebGUI/Form/HTMLArea.pm b/lib/WebGUI/Form/HTMLArea.pm index fee001c30..f901aeef3 100644 --- a/lib/WebGUI/Form/HTMLArea.pm +++ b/lib/WebGUI/Form/HTMLArea.pm @@ -213,7 +213,7 @@ Asset picker for the rich editor. sub www_pageTree { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); $session->style->setCss($session->url->extras('/tinymce-webgui/plugins/wgpagetree/css/pagetree.css')); $session->style->setRawHeadTags(<<"JS"); @@ -270,7 +270,7 @@ Each link display a thumbnail of the image via www_viewThumbnail. sub www_imageTree { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); $session->style->setCss($session->url->extras('/tinymce-webgui/plugins/wginsertimage/css/insertimage.css')); $session->style->setRawHeadTags(<<"JS"); @@ -349,7 +349,7 @@ URL in the session object is used to determine which Image is used. sub www_viewThumbnail { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); $session->style->setCss($session->url->extras('/tinymce-webgui/plugins/wginsertimage/css/insertimage.css')); my $image = WebGUI::Asset->newByUrl($session); my $i18n = WebGUI::International->new($session); @@ -375,7 +375,7 @@ Returns a form to add a folder using the rich editor. The purpose of this featur sub www_addFolder { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $i18n = WebGUI::International->new($session, 'Operation_FormHelpers'); my $f = WebGUI::HTMLForm->new($session); $f->hidden( @@ -416,7 +416,7 @@ Creates a directory under the current asset. The filename should be specified in sub www_addFolderSave { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); # get base url my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); # check if user can edit the current asset @@ -453,7 +453,7 @@ sub www_addFolderSave { #filename => $filename, }); WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { allowComments => 0 }); - $session->http->setRedirect($base->getUrl('op=formHelper;class=HTMLArea;sub=imageTree')); + $session->response->setRedirect($base->getUrl('op=formHelper;class=HTMLArea;sub=imageTree')); return undef; } @@ -467,7 +467,7 @@ Returns a form to add an image using the rich editor. The purpose of this featur sub www_addImage { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $i18n = WebGUI::International->new($session, 'Operation_FormHelpers'); my $f = WebGUI::HTMLForm->new($session); $f->hidden( @@ -508,7 +508,7 @@ Creates an Image asset under the current asset. The filename should be specified sub www_addImageSave { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); # get base asset my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session); @@ -539,7 +539,7 @@ sub www_addImageSave { $child->applyConstraints; } WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { allowComments => 0 }); - $session->http->setRedirect($base->getUrl('op=formHelper;class=HTMLArea;sub=imageTree')); + $session->response->setRedirect($base->getUrl('op=formHelper;class=HTMLArea;sub=imageTree')); return undef; } diff --git a/lib/WebGUI/Operation/AdSpace.pm b/lib/WebGUI/Operation/AdSpace.pm index 8b4a97b2c..4a77e8202 100644 --- a/lib/WebGUI/Operation/AdSpace.pm +++ b/lib/WebGUI/Operation/AdSpace.pm @@ -56,7 +56,7 @@ sub www_clickAd { my $id = $session->form->param("id"); return undef unless $id; my $url = WebGUI::AdSpace->countClick($session, $id); - $session->http->setRedirect($url); + $session->response->setRedirect($url); return undef; } diff --git a/lib/WebGUI/Operation/Admin.pm b/lib/WebGUI/Operation/Admin.pm index 97e6425ce..f01a20444 100644 --- a/lib/WebGUI/Operation/Admin.pm +++ b/lib/WebGUI/Operation/Admin.pm @@ -51,7 +51,7 @@ via WebGUI::Session::switchAdminOff() sub www_switchOffAdmin { my $session = shift; return "" unless ($session->user->canUseAdminMode); - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); $session->switchAdminOff(); return ""; } @@ -67,7 +67,7 @@ If the current user is in the Turn On Admin Group, then allow them to turn on Ad sub www_switchOnAdmin { my $session = shift; return "" unless ($session->user->canUseAdminMode); - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); $session->switchAdminOn(); return ""; } diff --git a/lib/WebGUI/Operation/Auth.pm b/lib/WebGUI/Operation/Auth.pm index 688a22a25..7498dc92f 100644 --- a/lib/WebGUI/Operation/Auth.pm +++ b/lib/WebGUI/Operation/Auth.pm @@ -69,7 +69,7 @@ is returned. sub www_auth { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $auth; ($auth) = $session->db->quickArray("select authMethod from users where username=".$session->db->quote($session->form->process("username"))) if($session->form->process("username")); my $authMethod = getInstance($session,$auth); diff --git a/lib/WebGUI/Operation/Cron.pm b/lib/WebGUI/Operation/Cron.pm index 9ec43f656..bd19d1cfc 100644 --- a/lib/WebGUI/Operation/Cron.pm +++ b/lib/WebGUI/Operation/Cron.pm @@ -270,7 +270,7 @@ Checks to ensure the requestor is who we think it is, and then executes a cron j sub www_runCronJob { my $session = shift; $session->response->content_type("text/plain"); - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); unless (Net::CIDR::Lite->new(@{ $session->config->get('spectreSubnets') })->find($session->request->address) || canView($session)) { $session->log->security("make a Spectre cron job runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")})."."); return "error"; diff --git a/lib/WebGUI/Operation/LDAPLink.pm b/lib/WebGUI/Operation/LDAPLink.pm index 83ce028c2..d034582b2 100644 --- a/lib/WebGUI/Operation/LDAPLink.pm +++ b/lib/WebGUI/Operation/LDAPLink.pm @@ -348,7 +348,7 @@ sub www_editLDAPLinkSave { $properties->{ldapLoginTemplate} = $session->form->template("ldapLoginTemplate"); $session->db->setRow("ldapLink","ldapLinkId",$properties); if($session->form->process("returnUrl")) { - $session->http->setRedirect($session->form->process("returnUrl")); + $session->response->setRedirect($session->form->process("returnUrl")); return undef; } return www_listLDAPLinks($session); diff --git a/lib/WebGUI/Operation/Spectre.pm b/lib/WebGUI/Operation/Spectre.pm index 0b63a3eab..46c073cf7 100644 --- a/lib/WebGUI/Operation/Spectre.pm +++ b/lib/WebGUI/Operation/Spectre.pm @@ -53,7 +53,7 @@ Checks to ensure the requestor is who we think it is, and then returns a JSON st sub www_spectreGetSiteData { my $session = shift; $session->response->content_type("application/json"); - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my %siteData = (); my $subnets = $session->config->get("spectreSubnets"); if (!defined $subnets) { @@ -117,7 +117,7 @@ sub www_spectreStatus { my $ac = WebGUI::AdminConsole->new($session, 'spectre'); my $i18n = WebGUI::International->new($session, 'Spectre'); - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $remote = create_ikc_client( port=>$session->config->get("spectrePort"), @@ -174,7 +174,7 @@ spectreSubnet, instead of checking the IP address of the spectre process. sub www_spectreTest { my $session = shift; $session->response->content_type("text/plain"); - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $subnets = $session->config->get("spectreSubnets"); if (!defined $subnets) { diff --git a/lib/WebGUI/Operation/User.pm b/lib/WebGUI/Operation/User.pm index 4d74d9d93..029c4c6ee 100644 --- a/lib/WebGUI/Operation/User.pm +++ b/lib/WebGUI/Operation/User.pm @@ -943,7 +943,7 @@ A reference to the current session. sub www_formUsers { my $session = shift; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); return $session->privilege->insufficient() unless $session->user->isInGroup(12); $session->style->useEmptyStyle("1"); my $output = getUserSearchForm($session,"formUsers",{formId=>$session->form->process("formId")},1); diff --git a/lib/WebGUI/Operation/VersionTag.pm b/lib/WebGUI/Operation/VersionTag.pm index 40437516d..7a6b0a124 100644 --- a/lib/WebGUI/Operation/VersionTag.pm +++ b/lib/WebGUI/Operation/VersionTag.pm @@ -912,7 +912,7 @@ sub www_rollbackVersionTag { my $method = $session->form->process("proceed"); $method = $method eq "manageCommittedVersions" ? $method : 'manageVersions'; my $redir = WebGUI::Asset->getDefault($session)->getUrl("op=$method"); - $session->http->setRedirect( + $session->response->setRedirect( $session->url->page( $process->contentPairs( 'ProgressBar', { diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index f68c73e11..a5be61ef2 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -482,7 +482,7 @@ Checks to ensure the requestor is who we think it is, and then executes a workfl sub www_runWorkflow { my $session = shift; $session->response->content_type("text/plain"); - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); unless (Net::CIDR::Lite->new(@{ $session->config->get('spectreSubnets')} )->find($session->request->address) || canRunWorkflow($session)) { $session->log->security("make a Spectre workflow runner request, but we're only allowed to accept requests from ".join(",",@{$session->config->get("spectreSubnets")})."."); return "error"; diff --git a/lib/WebGUI/PassiveAnalytics/Flow.pm b/lib/WebGUI/PassiveAnalytics/Flow.pm index 1ad5bfb73..5925a79dd 100644 --- a/lib/WebGUI/PassiveAnalytics/Flow.pm +++ b/lib/WebGUI/PassiveAnalytics/Flow.pm @@ -90,7 +90,7 @@ sub exportSomething { $csvData .= WebGUI::Text::joinCSV(@row) . "\n"; } $storage->addFileFromScalar($filename, $csvData); - $session->http->setRedirect($storage->getUrl($filename)); + $session->response->setRedirect($storage->getUrl($filename)); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/ProgressBar.pm b/lib/WebGUI/ProgressBar.pm index 1659341ba..b344e4f11 100644 --- a/lib/WebGUI/ProgressBar.pm +++ b/lib/WebGUI/ProgressBar.pm @@ -150,7 +150,7 @@ The url to the icon you want to display. sub start { my ($self, $title, $icon) = @_; - $self->session->http->setCacheControl("none"); + $self->session->response->setCacheControl("none"); my %var = ( title => $title, icon => $icon @@ -159,7 +159,7 @@ sub start { my $output = $self->session->style->process($template->process(\%var).'~~~', "PBtmpl0000000000000137"); my ($head, $foot) = split '~~~', $output; local $| = 1; # Tell modperl not to buffer the output - $self->session->http->sendHeader; + $self->session->response->sendHeader; $self->session->output->print($head, 1); #skipMacros $self->{_foot} = $foot; return ''; diff --git a/lib/WebGUI/Role/Asset/RssFeed.pm b/lib/WebGUI/Role/Asset/RssFeed.pm index 33c2e323c..54395003f 100644 --- a/lib/WebGUI/Role/Asset/RssFeed.pm +++ b/lib/WebGUI/Role/Asset/RssFeed.pm @@ -157,7 +157,7 @@ sub _httpBasicLogin { 'WWW-Authenticate' => 'Basic realm="'.$self->session->setting->get('companyName').'"' ); $self->session->response->status(401); - $self->session->http->sendHeader; + $self->session->response->sendHeader; return ''; } diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index d9dff6809..853824a71 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -571,6 +571,7 @@ sub open { ##Set defaults $self->{_response} = $request->new_response( 200 ); $self->{_response}->content_type('text/html; charset=UTF-8'); + $self->{_response}->session( $self ); # Use the WebGUI::Session::Request object to look up the sessionId from cookies, if it # wasn't given explicitly diff --git a/lib/WebGUI/Session/Http.pm b/lib/WebGUI/Session/Http.pm index e54d6c2bb..2e8ed5de5 100644 --- a/lib/WebGUI/Session/Http.pm +++ b/lib/WebGUI/Session/Http.pm @@ -33,6 +33,9 @@ Package WebGUI::Session::Http This package allows the manipulation of HTTP protocol information. +*** This module is deprecated in favor of L and +L. + =head1 SYNOPSIS use WebGUI::Session::Http; @@ -53,89 +56,6 @@ These methods are available from this package: =cut -#------------------------------------------------------------------- - -=head2 getCacheControl ( ) - -Returns the cache control setting from this object. - -=cut - -sub getCacheControl { - my $self = shift; - return $self->{_http}{cacheControl} || 1; -} - -#------------------------------------------------------------------- - -=head2 getCookies ( ) - -Retrieves the cookies from the HTTP header and returns a hash reference containing them. - -=cut - -sub getCookies { - my $self = shift; - _deprecated('Request::cookies'); - return $self->session->request->cookies; -} - - -#------------------------------------------------------------------- - -=head2 getLastModified ( ) - -Returns the stored epoch date when the page as last modified. - -=cut - -sub getLastModified { - my $self = shift; - return $self->{_http}{lastModified}; -} - -#------------------------------------------------------------------- - -=head2 getNoHeader ( ) - -Returns whether or not a HTTP header will be printed. - -=cut - -sub getNoHeader { - my $self = shift; - return $self->{_http}{noHeader}; -} - -#------------------------------------------------------------------- - -=head2 getStreamedFile ( ) { - -Returns the location of a file to be streamed thru mod_perl, if one has been set. - -=cut - -sub getStreamedFile { - my $self = shift; - return $self->{_http}{streamlocation} || undef; -} - - -#------------------------------------------------------------------- - -=head2 isRedirect ( ) - -Returns a boolean value indicating whether the current page will redirect to some other location. - -=cut - -sub isRedirect { - my $self = shift; - my $status = $self->session->response->status; - return $status == 302 || $status == 301; -} - - #------------------------------------------------------------------- =head2 new ( session ) @@ -156,76 +76,6 @@ sub new { return $self; } - -#------------------------------------------------------------------- - -=head2 sendHeader ( ) - -Generates and sends HTTP headers for a response. - -=cut - -sub sendHeader { - my $self = shift; - return undef if ($self->{_http}{noHeader}); - return $self->_sendMinimalHeader unless defined $self->session->db(1); - - my $session = $self->session; - my ($request, $response, $config) = $session->quick(qw(request response config )); - return undef unless $request; - my $userId = $session->get("userId"); - - # send webgui session cookie - my $cookieName = $config->getCookieName; - $self->setCookie($cookieName, $session->getId, $config->getCookieTTL, $config->get("cookieDomain")) unless $session->getId eq $request->cookies->{$cookieName}; - - $self->setNoHeader(1); - my %params; - if (!$self->isRedirect()) { - my $cacheControl = $self->getCacheControl; - my $date = ($userId eq "1") ? HTTP::Date::time2str($self->getLastModified) : HTTP::Date::time2str(); - # under these circumstances, don't allow caching - if ($userId ne "1" || $cacheControl eq "none" || $self->session->setting->get("preventProxyCache")) { - $response->header( - "Cache-Control" => "private, max-age=1", - "Pragma" => "no-cache", - "Cache-Control" => "no-cache", - ); - } - # in all other cases, set cache, but tell it to ask us every time so we don't mess with recently logged in users - else { - if ( $cacheControl eq "none" ) { - $response->header("Cache-Control" => "private, max-age=1"); - } - else { - $response->header( - 'Last-Modified' => $date, - 'Cache-Control' => "must-revalidate, max-age=" . $cacheControl, - ); - } - # do an extra incantation if the HTTP protocol is really old - if ($request->protocol =~ /(\d\.\d)/ && $1 < 1.1) { - my $date = HTTP::Date::time2str(time() + $cacheControl); - $response->header( 'Expires' => $date ); - } - } - } - return undef; -} - -sub _sendMinimalHeader { - my $self = shift; - my $response = $self->session->response; - $response->content_type('text/html; charset=UTF-8'); - $response->header( - 'Cache-Control' => 'private', - "Pragma" => "no-cache", - "Cache-Control" => "no-cache", - ); - return undef; -} - - #------------------------------------------------------------------- =head2 session ( ) @@ -239,6 +89,106 @@ sub session { return $self->{_session}; } + +#------------------------------------------------------------------- + +=head2 getCacheControl ( ) + +Returns the cache control setting from this object. + +=cut + +sub getCacheControl { + my $self = shift; + return $self->session->response->getCacheControl; +} + +#------------------------------------------------------------------- + +=head2 getCookies ( ) + +Retrieves the cookies from the HTTP header and returns a hash reference containing them. + +=cut + +sub getCookies { + my $self = shift; + _deprecated('Session::Request::cookies'); + return $self->session->request->cookies; +} + + +#------------------------------------------------------------------- + +=head2 getLastModified ( ) + +Returns the stored epoch date when the page as last modified. + +=cut + +sub getLastModified { + my $self = shift; + return $self->session->response->getLastModified; +} + +#------------------------------------------------------------------- + +=head2 getNoHeader ( ) + +Returns whether or not a HTTP header will be printed. + +=cut + +sub getNoHeader { + my $self = shift; + return $self->session->response->getNoHeader; +} + +#------------------------------------------------------------------- + +=head2 getStreamedFile ( ) { + +Returns the location of a file to be streamed thru mod_perl, if one has been set. + +=cut + +sub getStreamedFile { + my $self = shift; + _deprecated('Session::Response::getStreamedFile'); + return $self->session->response->getStreamedFile; +} + + +#------------------------------------------------------------------- + +=head2 isRedirect ( ) + +Returns a boolean value indicating whether the current page will redirect to some other location. + +=cut + +sub isRedirect { + my $self = shift; + _deprecated('Session::Response::isRedirect'); + return $self->session->response->isRedirect; +} + + +#------------------------------------------------------------------- + +=head3 sendHeader + +Moved to L. + +=cut + +sub sendHeader { + my $self = shift; + _deprecated('Session::Response::sendHeader'); + $self->session->response->sendHeader(@_); +} + + #------------------------------------------------------------------- =head2 setCacheControl ( timeout ) @@ -253,49 +203,20 @@ Either the number of seconds until the cache expires, or the word "none" to disa sub setCacheControl { my $self = shift; - my $timeout = shift; - $self->{_http}{cacheControl} = $timeout; + _deprecated('Session::Response::setCacheControl'); + $self->session->response->setCacheControl(@_); } #------------------------------------------------------------------- =head2 setCookie ( name, value [ , timeToLive, domain ] ) -Sends a cookie to the browser. - -=head3 name - -The name of the cookie to set. Must be unique from all other cookies from this domain or it will overwrite that cookie. - -=head3 value - -The value to set. - -=head3 timeToLive - -The time that the cookie should remain in the browser. Defaults to "+10y" (10 years from now). -This may be "session" to indicate that the cookie is for the current browser session only. - -=head3 domain - -Explicitly set the domain for this cookie. - -=cut +Moved to L. sub setCookie { my $self = shift; - my $name = shift; - my $value = shift; - my $ttl = shift; - my $domain = shift; - $ttl = (defined $ttl ? $ttl : '+10y'); - - $self->session->response->cookies->{$name} = { - value => $value, - path => '/', - expires => $ttl ne 'session' ? $ttl : undef, - domain => $domain, - }; + _deprecated('Session::Request'); + $self->session->response->setCookie(@_); } @@ -311,8 +232,8 @@ The epoch date when the page was last modified. sub setLastModified { my $self = shift; - my $epoch = shift; - $self->{_http}{lastModified} = $epoch; + _deprecated('Session::Response::setLastModified'); + $self->session->response->setLastModified(@_); } #------------------------------------------------------------------- @@ -330,36 +251,22 @@ Any value other than 0 will disable header printing. sub setNoHeader { my $self = shift; - $self->{_http}{noHeader} = shift; + _deprecated('Session::Response::setNoHeader'); + $self->session->response->setNoHeader(@_); } #------------------------------------------------------------------- =head2 setRedirect ( url, [ type ] ) -Sets the necessary information in the HTTP header to redirect to another URL. - -=head3 url - -The URL to redirect to. To prevent infinite loops, no redirect will be set if -url is the same as the current page, as found through $session->url->page. - -=head3 type - -Defaults to 302 (temporary redirect), but you can optionally set 301 (permanent redirect). +Moved to L. =cut sub setRedirect { my $self = shift; - my $url = shift; - my $type = shift || 302; - my @params = $self->session->form->param; - return undef if ($url eq $self->session->url->page() && scalar(@params) < 1); # prevent redirecting to self - $self->session->log->info("Redirecting to $url"); - $self->session->response->location($url); - $self->session->response->status($type); - $self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$url}); + _deprecated('Session::Response'); + $self->session->response->setRedirect(@_); } @@ -373,7 +280,8 @@ Set a file to be streamed thru mod_perl. sub setStreamedFile { my $self = shift; - $self->{_http}{streamlocation} = shift; + _deprecated('Session::Response'); + $self->session->response->setStreamedFile(@_); } diff --git a/lib/WebGUI/Session/Response.pm b/lib/WebGUI/Session/Response.pm index 5af0d5d79..19b2641a7 100644 --- a/lib/WebGUI/Session/Response.pm +++ b/lib/WebGUI/Session/Response.pm @@ -1,7 +1,12 @@ package WebGUI::Session::Response; + use strict; +use warnings; + use parent qw(Plack::Response); +use IO::File::WithPath; + use Plack::Util::Accessor qw(session streaming writer streamer); =head1 SYNOPSIS @@ -18,6 +23,10 @@ is created. =cut +# +# +# + =head2 stream =cut @@ -28,6 +37,10 @@ sub stream { $self->streaming(1); } +# +# +# + =head2 stream_write =cut @@ -41,4 +54,300 @@ sub stream_write { $self->writer->write(@_); } +# +# +# + +=head2 sendHeader ( ) + +Generates and sends HTTP headers for a response. + +=cut + +sub sendHeader { + my $self = shift; + return undef if $self->{_http}{noHeader}; + return $self->_sendMinimalHeader unless defined $self->session->db(1); + + no warnings 'uninitialized'; + + my $session = $self->session; + my ($request, $config) = $session->quick(qw(request config )); + return undef unless $request; + my $userId = $session->get("userId"); + + # send webgui session cookie + my $cookieName = $config->getCookieName; + $self->setCookie($cookieName, $session->getId, $config->getCookieTTL, $config->get("cookieDomain")) unless $session->getId eq $request->cookies->{$cookieName}; + + $self->setNoHeader(1); + my %params; + if (!$self->isRedirect()) { + my $cacheControl = $self->getCacheControl; + my $date = ($userId eq "1") ? HTTP::Date::time2str($self->getLastModified) : HTTP::Date::time2str(); + # under these circumstances, don't allow caching + if ($userId ne "1" || $cacheControl eq "none" || $self->session->setting->get("preventProxyCache")) { + $self->header( + "Cache-Control" => "private, max-age=1", + "Pragma" => "no-cache", + "Cache-Control" => "no-cache", + ); + } + # in all other cases, set cache, but tell it to ask us every time so we don't mess with recently logged in users + else { + if ( $cacheControl eq "none" ) { + $self->header("Cache-Control" => "private, max-age=1"); + } + else { + $self->header( + 'Last-Modified' => $date, + 'Cache-Control' => "must-revalidate, max-age=" . $cacheControl, + ); + } + # do an extra incantation if the HTTP protocol is really old + if ($request->protocol =~ /(\d\.\d)/ && $1 < 1.1) { + my $date = HTTP::Date::time2str(time() + $cacheControl); + $self->header( 'Expires' => $date ); + } + } + } + return undef; +} + +sub _sendMinimalHeader { + my $self = shift; + $self->content_type('text/html; charset=UTF-8'); + $self->header( + 'Cache-Control' => 'private', + "Pragma" => "no-cache", + "Cache-Control" => "no-cache", + ); + return undef; +} + +# +# +# + +=head2 setCookie ( name, value [ , timeToLive, domain ] ) + +Sends a cookie to the browser. + +=head3 name + +The name of the cookie to set. Must be unique from all other cookies from this domain or it will overwrite that cookie. + +=head3 value + +The value to set. + +=head3 timeToLive + +The time that the cookie should remain in the browser. Defaults to "+10y" (10 years from now). +This may be "session" to indicate that the cookie is for the current browser session only. + +=head3 domain + +Explicitly set the domain for this cookie. + +=cut + +sub setCookie { + my $self = shift; + my $name = shift; + my $value = shift; + my $ttl = shift; + my $domain = shift; + $ttl = (defined $ttl ? $ttl : '+10y'); + + $self->cookies->{$name} = { + value => $value, + path => '/', + expires => $ttl ne 'session' ? $ttl : undef, + domain => $domain, + }; +} + +# +# +# + +=head2 setRedirect ( url, [ type ] ) + +Sets the necessary information in the HTTP header to redirect to another URL. + +=head3 url + +The URL to redirect to. To prevent infinite loops, no redirect will be set if +url is the same as the current page, as found through $session->url->page. + +=head3 type + +Defaults to 302 (temporary redirect), but you can optionally set 301 (permanent redirect). + +=cut + +sub setRedirect { + my $self = shift; + my $url = shift || ''; + my $type = shift || 302; + my @params = $self->session->form->param; + return undef if ($url eq $self->session->url->page() && scalar(@params) < 1); # prevent redirecting to self + $self->session->log->info("Redirecting to $url"); + $self->location($url); + $self->status($type); + $self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$url}); +} + +# +# +# + +=head2 getLastModified ( ) + +Returns the stored epoch date when the page as last modified. + +=cut + +sub getLastModified { + my $self = shift; + return $self->{_http}{lastModified}; +} + +# +# +# + +=head2 setLastModified ( epoch ) + +=head3 epoch + +The epoch date when the page was last modified. + +=cut + +sub setLastModified { + my $self = shift; + my $epoch = shift; + $self->{_http}{lastModified} = $epoch; +} + +# +# +# + +=head2 getNoHeader ( ) + +Returns whether or not a HTTP header will be printed. + +=cut + +sub getNoHeader { + my $self = shift; + return $self->{_http}{noHeader}; +} + +# +# +# + +=head2 setNoHeader ( boolean ) + +Disables the printing of a HTTP header. Useful in situations when content is not +returned to a browser (export to disk for example). + +=head3 boolean + +Any value other than 0 will disable header printing. + +=cut + +sub setNoHeader { + my $self = shift; + $self->{_http}{noHeader} = shift; +} + +# +# +# + +=head2 isRedirect ( ) + +Returns a boolean value indicating whether the current page will redirect to some other location. + +=cut + +sub isRedirect { + my $self = shift; + my $status = $self->status; + return $status == 302 || $status == 301; +} + +# +# +# + +=head2 getStreamedFile ( ) { + +Returns the location of a file to be streamed thru mod_perl, if one has been set. + +=cut + +sub getStreamedFile { + my $self = shift; + return $self->{_http}{streamlocation} || undef; +} + +# +# +# + +=head2 setStreamedFile ( ) { + +Set a file to be streamed thru mod_perl. + +=cut + +sub setStreamedFile { + my $self = shift; + my $fn = shift; + $self->{_http}{streamlocation} = $fn; + # $self->body( IO::File::WithPath->new( $fn ) ); # let Plack handle the streaming, or let Plack::Middleware::XSendfile punt it; we don't want to send a 302 header and send the file, too; should be one or the other, selectable +} + +# +# +# + +=head2 setCacheControl ( timeout ) + +Sets the cache control headers. + +=head3 timeout + +Either the number of seconds until the cache expires, or the word "none" to disable cache completely for this request. + +=cut + +sub setCacheControl { + my $self = shift; + my $timeout = shift; + $self->{_http}{cacheControl} = $timeout; +} + +# +# +# + +=head2 getCacheControl ( ) + +Returns the cache control setting from this object. + +=cut + +sub getCacheControl { + my $self = shift; + return $self->{_http}{cacheControl} || 1; +} + 1; diff --git a/lib/WebGUI/Session/Style.pm b/lib/WebGUI/Session/Style.pm index b4f49980a..f159e260f 100644 --- a/lib/WebGUI/Session/Style.pm +++ b/lib/WebGUI/Session/Style.pm @@ -242,7 +242,7 @@ if ($self->session->user->isRegistered || $self->session->setting->get("preventP '; - $self->session->http->setCacheControl("none"); + $self->session->response->setCacheControl("none"); } else { $var{'head.tags'} .= '' } @@ -559,7 +559,7 @@ The content to be wrappered. sub userStyle { my $self = shift; my $output = shift; - $self->session->http->setCacheControl("none"); + $self->session->response->setCacheControl("none"); if (defined $output) { return $self->process($output,$self->session->setting->get("userFunctionStyleId")); } else { diff --git a/lib/WebGUI/Session/Url.pm b/lib/WebGUI/Session/Url.pm index 347edd048..22deb62c6 100644 --- a/lib/WebGUI/Session/Url.pm +++ b/lib/WebGUI/Session/Url.pm @@ -288,7 +288,7 @@ is not passed in, it will attempt to get one from the L method, or finally sub forceSecureConnection { my $self = shift; my $url = shift; - my ($conf, $http) = $self->session->quick(qw(config http)); + my ($conf, $response) = $self->session->quick(qw(config response)); if ($conf->get("sslEnabled") && ! $self->session->request->secure){ @@ -305,7 +305,7 @@ sub forceSecureConnection { } if($url =~ /^http/i) { $url =~ s/^https?/https/i; - $http->setRedirect($url); + $response->setRedirect($url); return 1; } } diff --git a/lib/WebGUI/Shop/PayDriver.pm b/lib/WebGUI/Shop/PayDriver.pm index fd472248d..5b28fca86 100644 --- a/lib/WebGUI/Shop/PayDriver.pm +++ b/lib/WebGUI/Shop/PayDriver.pm @@ -668,7 +668,7 @@ sub www_editSave { return $session->privilege->insufficient() unless $session->user->isAdmin; $self->processPropertiesFromFormPost; - $session->http->setRedirect($session->url->page('shop=pay;method=manage')); + $session->response->setRedirect($session->url->page('shop=pay;method=manage')); return undef; } diff --git a/lib/WebGUI/Shop/PayDriver/Ogone.pm b/lib/WebGUI/Shop/PayDriver/Ogone.pm index 7ba780049..e62ef0208 100644 --- a/lib/WebGUI/Shop/PayDriver/Ogone.pm +++ b/lib/WebGUI/Shop/PayDriver/Ogone.pm @@ -350,7 +350,7 @@ sub www_cancelTransaction { $self->_setPaymentStatus( 0, $form->process('PAYID'), $form->process('STATUS'), 'Cancelled' ); $self->processTransaction( $transaction ); - $session->http->setRedirect($self->session->url->getSiteURL.'?shop=cart'); + $session->response->setRedirect($self->session->url->getSiteURL.'?shop=cart'); return $session->style->userStyle('Transaction cancelled'); } @@ -373,7 +373,7 @@ sub www_declineTransaction { $self->_setPaymentStatus( 0, $form->process('PAYID'), $form->process('STATUS'), 'Declined' ); $self->processTransaction( $transaction ); - $session->http->setRedirect($self->session->url->getSiteURL.'?shop=cart'); + $session->response->setRedirect($self->session->url->getSiteURL.'?shop=cart'); return $session->style->userStyle('Transaction declined'); } @@ -396,7 +396,7 @@ sub www_exceptionTransaction { $self->_setPaymentStatus( 0, $form->process('PAYID'), $form->process('STATUS'), 'Transaction exception occurred' ); $self->processTransaction( $transaction ); - $session->http->setRedirect($self->session->url->getSiteURL.'?shop=cart'); + $session->response->setRedirect($self->session->url->getSiteURL.'?shop=cart'); return $session->style->userStyle('A transaction exception occurred.'); } diff --git a/lib/WebGUI/Shop/PayDriver/PayPal/ExpressCheckout.pm b/lib/WebGUI/Shop/PayDriver/PayPal/ExpressCheckout.pm index ff7023e9e..cf7439bd9 100644 --- a/lib/WebGUI/Shop/PayDriver/PayPal/ExpressCheckout.pm +++ b/lib/WebGUI/Shop/PayDriver/PayPal/ExpressCheckout.pm @@ -337,7 +337,7 @@ sub www_sendToPayPal { } ); - return $session->http->setRedirect($dest); + return $session->response->setRedirect($dest); } ## end sub www_sendToPayPal =head1 LIMITATIONS diff --git a/lib/WebGUI/Shop/ShipDriver.pm b/lib/WebGUI/Shop/ShipDriver.pm index 390cbc08f..5d10c6a43 100644 --- a/lib/WebGUI/Shop/ShipDriver.pm +++ b/lib/WebGUI/Shop/ShipDriver.pm @@ -346,7 +346,7 @@ sub www_editSave { my $session = $self->session; return $session->privilege->insufficient() unless $session->user->isAdmin; $self->processPropertiesFromFormPost; - $session->http->setRedirect($session->url->page('shop=ship;method=manage')); + $session->response->setRedirect($session->url->page('shop=ship;method=manage')); return undef; } diff --git a/lib/WebGUI/Shop/TaxDriver/Generic.pm b/lib/WebGUI/Shop/TaxDriver/Generic.pm index ffc45b574..ad26ec882 100644 --- a/lib/WebGUI/Shop/TaxDriver/Generic.pm +++ b/lib/WebGUI/Shop/TaxDriver/Generic.pm @@ -437,7 +437,7 @@ sub www_exportTax { return $session->privilege->insufficient unless $self->canManage; my $storage = $self->exportTaxData(); - $self->session->http->setRedirect($storage->getUrl($storage->getFiles->[0])); + $self->session->response->setRedirect($storage->getUrl($storage->getFiles->[0])); return "redirect"; } diff --git a/lib/WebGUI/VersionTag.pm b/lib/WebGUI/VersionTag.pm index f334c6316..77aea9dc7 100644 --- a/lib/WebGUI/VersionTag.pm +++ b/lib/WebGUI/VersionTag.pm @@ -100,7 +100,7 @@ sub autoCommitWorkingIfEnabled { } else { my $url = $versionTag->autoCommitUrl($options->{returnUrl}); - $session->http->setRedirect($url); + $session->response->setRedirect($url); return 'redirect'; } } diff --git a/lib/WebGUI/Wizard.pm b/lib/WebGUI/Wizard.pm index 5f07f981d..cdff82c65 100644 --- a/lib/WebGUI/Wizard.pm +++ b/lib/WebGUI/Wizard.pm @@ -377,7 +377,7 @@ sub www_cleanup { my ( $self ) = @_; $self->cleanup; - $self->session->http->setRedirect( $self->session->url->page ); + $self->session->response->setRedirect( $self->session->url->page ); return "redirect"; } diff --git a/lib/WebGUI/Wizard/HomePage.pm b/lib/WebGUI/Wizard/HomePage.pm index 936310553..b01db1e86 100644 --- a/lib/WebGUI/Wizard/HomePage.pm +++ b/lib/WebGUI/Wizard/HomePage.pm @@ -242,7 +242,7 @@ sub www_chooseContent { my ($self) = @_; my $session = $self->session; my $form = $session->form; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $i18n = WebGUI::International->new( $session, "WebGUI" ); my $output = '

' . $i18n->get('Initial Pages') . '

'; diff --git a/lib/WebGUI/Wizard/Setup.pm b/lib/WebGUI/Wizard/Setup.pm index 5baede6df..8591a83b0 100644 --- a/lib/WebGUI/Wizard/Setup.pm +++ b/lib/WebGUI/Wizard/Setup.pm @@ -57,7 +57,7 @@ sub wrapStyle { my ( $self, $output ) = @_; my $session = $self->session; my $form = $session->form; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $i18n = WebGUI::International->new( $session, "WebGUI" ); my $page = ' @@ -142,7 +142,7 @@ sub www_adminAccount { my ( $self ) = @_; my $session = $self->session; my $form = $session->form; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $i18n = WebGUI::International->new( $session, "WebGUI" ); my $legend = $i18n->get('admin account'); @@ -246,7 +246,7 @@ sub www_companyInformation { my ( $self ) = @_; my $session = $self->session; my $form = $session->form; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $i18n = WebGUI::International->new( $session, "WebGUI" ); my $output = '

' . $i18n->get('company information') . '

'; @@ -306,7 +306,7 @@ sub www_siteStats { my ( $self ) = @_; my $session = $self->session; my $form = $session->form; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $i18n = WebGUI::International->new( $session, "WebGUI" ); my $enableForm = $self->getForm; @@ -390,7 +390,7 @@ sub www_cleanup { my ( $self ) = @_; my $session = $self->session; my $form = $session->form; - $session->http->setCacheControl("none"); + $session->response->setCacheControl("none"); my $i18n = WebGUI::International->new( $session, "WebGUI" ); $self->cleanup; diff --git a/sbin/testEnvironment.pl b/sbin/testEnvironment.pl index 190fa63b6..f60a3fee0 100755 --- a/sbin/testEnvironment.pl +++ b/sbin/testEnvironment.pl @@ -170,6 +170,7 @@ checkModule('Starman', '0.2010', 2); checkModule('App::Cmd', '0.311' ); checkModule('Devel::StackTrace', '1.27' ); checkModule('Devel::StackTrace::WithLexicals', '0.03' ); +checkModule('IO::File::WithPath', ); failAndExit("Required modules are missing, running no more checks.") if $missingModule; diff --git a/t/Session/Http.t b/t/Session/Http.t index c067dd72d..a97c676e7 100644 --- a/t/Session/Http.t +++ b/t/Session/Http.t @@ -8,6 +8,11 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- +# this test file is now slightly badly named since the functions in +# WebGUI::Session::HTTML have all been migrated to +# WebGUI::Session::Request and ::Response. still, these tests need +# to continue to pass. + use strict; use WebGUI::Test; diff --git a/t/Session/Style.t b/t/Session/Style.t index ea1c8b58c..adabfb459 100644 --- a/t/Session/Style.t +++ b/t/Session/Style.t @@ -195,7 +195,7 @@ $session->setting->set('userFunctionStyleId', $templates->{user}->getId); is($style->userStyle('userStyle'), 'USER PRINTABLE STYLE TEMPLATE:userStyle', 'userStyle returns templated output according to userFunctionStyleId in settings'); -is($session->http->{_http}{cacheControl}, 'none', 'userStyle(via process): HTTP cacheControl set to none to prevent proxying'); +is($session->http->getCacheControl, 'none', 'userStyle(via process): HTTP cacheControl set to none to prevent proxying'); is($style->userStyle('userStyle'), 'USER PRINTABLE STYLE TEMPLATE:userStyle', 'userStyle returns templated output according to userFunctionStyleId in settings'); @@ -306,8 +306,7 @@ $head =~ s/(^HEAD=.+$)/$1/s; cmp_bag(\@metas, $expectedMetas, 'process:default meta tags with no caching head tags, preventProxyCache setting'); $session->setting->set('preventProxyCache', $origPreventProxyCache); -##No accessor -is($session->http->{_http}{cacheControl}, 'none', 'process: HTTP cacheControl set to none to prevent proxying'); +is($session->http->getCacheControl, 'none', 'process: HTTP cacheControl set to none to prevent proxying'); #################################################### # From 96bb1944029ef2c04e5e69ecc2469c569207bb65 Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Wed, 11 May 2011 16:26:32 -0400 Subject: [PATCH 6/7] Change newByDynamicClass calls that creept in back to newById, except for the ones in doc/upgrade. Kinda important. --- lib/WebGUI/Auth/WebGUI.pm | 2 +- lib/WebGUI/Workflow/Activity/NotifyAboutVersionTag.pm | 2 +- .../Workflow/Activity/RequestApprovalForVersionTag.pm | 2 +- sbin/diskUsage.pl | 2 +- sbin/findBrokenAssets.pl | 6 +++--- sbin/galleryImport.pl | 4 ++-- sbin/generateContent.pl | 2 +- t/Asset/File/GalleryFile/Photo/edit.t | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/WebGUI/Auth/WebGUI.pm b/lib/WebGUI/Auth/WebGUI.pm index 3a9a94039..fe2a13a86 100644 --- a/lib/WebGUI/Auth/WebGUI.pm +++ b/lib/WebGUI/Auth/WebGUI.pm @@ -1127,7 +1127,7 @@ sub www_emailRecoverPasswordFinish { my $mail = WebGUI::Mail::Send->create($session, { to=>$email, subject=>$i18n->get('WebGUI password recovery')}); my $vars = { }; $vars->{recoverPasswordUrl} = $session->url->append($session->url->getSiteURL,'op=auth;method=emailResetPassword;token='.$recoveryGuid); - my $template = WebGUI::Asset->newByDynamicClass($session, $session->setting->get('webguiPasswordRecoveryEmailTemplate')); + my $template = WebGUI::Asset->newById($session, $session->setting->get('webguiPasswordRecoveryEmailTemplate')); my $emailText = $template->process($vars); WebGUI::Macro::process($session, \$emailText); $mail->addText($emailText); diff --git a/lib/WebGUI/Workflow/Activity/NotifyAboutVersionTag.pm b/lib/WebGUI/Workflow/Activity/NotifyAboutVersionTag.pm index 12b500709..0576dfee6 100644 --- a/lib/WebGUI/Workflow/Activity/NotifyAboutVersionTag.pm +++ b/lib/WebGUI/Workflow/Activity/NotifyAboutVersionTag.pm @@ -108,7 +108,7 @@ sub execute { comments => $versionTag->get('comments'), url => $urlOfSingleAsset, }; - my $template = WebGUI::Asset->newByDynamicClass($self->session, $self->get('templateId')); + my $template = WebGUI::Asset->newById($self->session, $self->get('templateId')); my $message = $template->process($var); my $properties = { status=>"completed", diff --git a/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm b/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm index dee69eba0..d80014d33 100644 --- a/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm +++ b/lib/WebGUI/Workflow/Activity/RequestApprovalForVersionTag.pm @@ -295,7 +295,7 @@ sub sendMessage { comments => $versionTag->get('comments'), url => $approvalUrl, }; - my $template = WebGUI::Asset->newByDynamicClass($self->session, $self->get('templateId')); + my $template = WebGUI::Asset->newById($self->session, $self->get('templateId')); my $messageText = $template->process($var); for my $groupId ( @{ $self->getGroupToApprove } ) { my $message diff --git a/sbin/diskUsage.pl b/sbin/diskUsage.pl index 5ee66645b..e3fd452ba 100755 --- a/sbin/diskUsage.pl +++ b/sbin/diskUsage.pl @@ -66,7 +66,7 @@ sub du { my $totalSize; # disk space used if ($assetId) { # They specified an assetId to start with - $asset = WebGUI::Asset->newByDynamicClass($session,$assetId); + $asset = WebGUI::Asset->newById($session,$assetId); die ("Unable to instanciate asset $assetId") unless defined $asset; print "\nStarting with asset $assetId...\n" unless $quiet; } diff --git a/sbin/findBrokenAssets.pl b/sbin/findBrokenAssets.pl index 9ecaaab32..627ebf3e6 100644 --- a/sbin/findBrokenAssets.pl +++ b/sbin/findBrokenAssets.pl @@ -104,8 +104,8 @@ while ( my %row = $sth->hash ) { print "Fixed.\n"; # Make sure we have a valid parent - unless ( WebGUI::Asset->newByDynamicClass( $session, $row{parentId} ) ) { - my $asset = WebGUI::Asset->newByDynamicClass( $session, $row{assetId} ); + unless ( WebGUI::Asset->newById( $session, $row{parentId} ) ) { + my $asset = WebGUI::Asset->newById( $session, $row{assetId} ); $asset->setParent( WebGUI::Asset->getImportNode( $session ) ); print "\tNOTE: Invalid parent. Asset moved to Import Node\n"; } @@ -136,7 +136,7 @@ while ( my %row = $sth->hash ) { printf "%10s: %s\n", "class", $row{className}; # Parent - if ( my $parent = WebGUI::Asset->newByDynamicClass( $session, $row{parentId} ) ) { + if ( my $parent = WebGUI::Asset->newById( $session, $row{parentId} ) ) { printf "%10s: %s (%s)\n", "parent", $parent->getTitle, $parent->getId; } elsif ( $session->db->quickScalar( "SELECT * FROM asset WHERE assetId=?", [$row{parentId}] ) ) { diff --git a/sbin/galleryImport.pl b/sbin/galleryImport.pl index 9f4b7bbec..d62834193 100755 --- a/sbin/galleryImport.pl +++ b/sbin/galleryImport.pl @@ -64,7 +64,7 @@ if ( $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery') ) { else { my $fromAsset = undef; if (defined $fromAssetId) { - $fromAsset = WebGUI::Asset->newByDynamicClass($session, $fromAssetId); + $fromAsset = WebGUI::Asset->newById($session, $fromAssetId); } else { $fromAsset = WebGUI::Asset->newByUrl($session, $fromAssetUrl); @@ -241,7 +241,7 @@ sub addAlbumFromFolder { } ); for my $fileId ( @{ $fileIds } ) { - my $oldFile = WebGUI::Asset->newByDynamicClass( $session, $fileId ); + my $oldFile = WebGUI::Asset->newById( $session, $fileId ); my $oldStorage = $oldFile->getStorageLocation; my $className = $gallery->getAssetClassForFile( $oldStorage->getPath( $oldFile->get('filename') ) ); if ( !$className ) { diff --git a/sbin/generateContent.pl b/sbin/generateContent.pl index 69c9f70fe..17af71402 100755 --- a/sbin/generateContent.pl +++ b/sbin/generateContent.pl @@ -47,7 +47,7 @@ if ($url) { $asset = WebGUI::Asset->newByUrl($session,$url); } else { - $asset = WebGUI::Asset->newByDynamicClass($session,$assetId); + $asset = WebGUI::Asset->newById($session,$assetId); } if (defined $asset) { diff --git a/t/Asset/File/GalleryFile/Photo/edit.t b/t/Asset/File/GalleryFile/Photo/edit.t index 1d4aa7345..4f7e9909d 100644 --- a/t/Asset/File/GalleryFile/Photo/edit.t +++ b/t/Asset/File/GalleryFile/Photo/edit.t @@ -148,7 +148,7 @@ $mech->submit_form_ok({ }, 'Submit Photo edit form' ); # Re-create instance of Photo asset -$photo = WebGUI::Asset->newByDynamicClass($session, $photo->getId); +$photo = WebGUI::Asset->newById($session, $photo->getId); # Check whether properties were changed correctly cmp_deeply($photo->get, superhashof(\%properties), 'All changes applied'); From 7a994b59cea7bd6b0bc375db2888d58d59f879e3 Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Thu, 12 May 2011 20:09:04 -0400 Subject: [PATCH 7/7] 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. --- lib/WebGUI/Asset/File.pm | 7 +-- lib/WebGUI/Content/Asset.pm | 13 ----- lib/WebGUI/Session/Response.pm | 95 ++++++++++++++++++++++++++++++++-- share/site.psgi | 9 +++- t/PSGI/Http.t | 68 ++++++++++++++++++++++++ t/Session/Http.t | 17 ++++-- 6 files changed, 184 insertions(+), 25 deletions(-) create mode 100644 t/PSGI/Http.t diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index f1b49f8b1..47dc5addf 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -619,9 +619,10 @@ sub www_view { return sprintf($i18n->get("file not found"), $self->getUrl()); } - $session->response->setRedirect($self->getFileUrl) unless $session->config->get('enableStreamingUploads'); - $session->response->setStreamedFile($self->getStorageLocation->getPath($self->filename)); - $session->response->sendHeader; + # sendFile does either a redirect or starts a stream depending on how we're configured + + $session->response->sendFile($self->getStorageLocation, $self->filename); + return 'chunked'; } diff --git a/lib/WebGUI/Content/Asset.pm b/lib/WebGUI/Content/Asset.pm index f1d4929a4..999ff8103 100644 --- a/lib/WebGUI/Content/Asset.pm +++ b/lib/WebGUI/Content/Asset.pm @@ -176,19 +176,6 @@ sub handler { else { $output = dispatch($session, getRequestedAssetUrl($session)); } - - my $filename = $session->response->getStreamedFile(); - if ((defined $filename) && ($config->get("enableStreamingUploads") eq "1")) { - my $ct = guess_media_type($filename); - my $oldContentType = $request->content_type($ct); - if ($request->sendfile($filename) ) { - return; # TODO - what should we return to indicate streaming? - } - else { - $request->content_type($oldContentType); - } - } - return $output; } diff --git a/lib/WebGUI/Session/Response.pm b/lib/WebGUI/Session/Response.pm index 19b2641a7..11d516e3c 100644 --- a/lib/WebGUI/Session/Response.pm +++ b/lib/WebGUI/Session/Response.pm @@ -6,6 +6,8 @@ use warnings; use parent qw(Plack::Response); use IO::File::WithPath; +use Class::C3; +use LWP::MediaTypes; use Plack::Util::Accessor qw(session streaming writer streamer); @@ -212,7 +214,7 @@ Returns the stored epoch date when the page as last modified. sub getLastModified { my $self = shift; return $self->{_http}{lastModified}; -} +} # # @@ -304,15 +306,65 @@ sub getStreamedFile { =head2 setStreamedFile ( ) { -Set a file to be streamed thru mod_perl. - +Set a file to be streamed through mod_perl. +Rrequires that C be set in the config file and then +some middleware or reverse-proxy in front of L to catch the X-Sendfile +headers and replace that with the file to be sent. + =cut sub setStreamedFile { my $self = shift; my $fn = shift; + + if( ! defined $fn or ! length $fn ) { + # t/Session/Http.t tests that it can call this with '' as an arg + # really, it looks like it is testing implementation rather than behavior but I don't know what behavior it's getting at so, voodoo + $self->body(undef); + $self->{_http}{streamlocation} = undef; + return; + } + $self->{_http}{streamlocation} = $fn; - # $self->body( IO::File::WithPath->new( $fn ) ); # let Plack handle the streaming, or let Plack::Middleware::XSendfile punt it; we don't want to send a 302 header and send the file, too; should be one or the other, selectable + + # return undef unless $self->session->config->get('enableStreamingUploads'); # throw an error? handle gracefully? XX + + my $fh = eval { IO::File::WithPath->new( $fn ) } or WebGUI::Error::InvalidFile->throw( + error => "Couldn't create an IO::File::WithPath object: $@ $!", + brokenFile => $fn, + ); + + $self->body( $fh ); + + 1; + +} + +# +# +# + +=head2 sendFile ( ) { + +Either redirect (C) or trigger a stream (C) depending on how L is configured. +If C is set in the config file, C is used. + +=cut + +# $session->response->sendFile($self->getStorageLocation, $self->filename); + + +sub sendFile { + my $self = shift; + my $storage = shift; + my $filename = shift; + if( $self->session->config->get('enableStreamingUploads') ) { + $self->setStreamedFile( $storage->getPath($filename) ); + } + else { + $self->setRedirect( $storage->getUrl($filename) ); + } + 1; } # @@ -350,4 +402,39 @@ sub getCacheControl { return $self->{_http}{cacheControl} || 1; } +=head2 finalize ( ) + +Subclasses Plack::Response C, doing L specific finalization chores. + +=cut + +# +# +# + +sub finalize { + + my $self = shift; + + my $filename = $self->getStreamedFile(); + if (defined $filename and $self->session->config->get("enableStreamingUploads") ) { + # at this point, $request->body contains an IO::File::WithPath object, and that's all Plack needs + my $ct = LWP::MediaTypes::guess_media_type($filename); + $self->content_type($ct); + } + + # in the future, sendHeader's logic should be moved into here and sendHeader should vanish. + # the rest of WebGUI should essentially never need to call sendHeader explicitly but should + # just call methods in here to configure the response and then return back up to the top where + # WebGUI.pm calls finalize and returns the response object back to Plack. + # for now, I've added this extra (harmless) call to sendHeader to get started on removing the + # others. + + $self->sendHeader(); # doesn't send the header, only fixes the response up based on options set + + $self->next::method(@_); + +} + + 1; diff --git a/share/site.psgi b/share/site.psgi index 9c553b73a..85709bb60 100644 --- a/share/site.psgi +++ b/share/site.psgi @@ -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; diff --git a/t/PSGI/Http.t b/t/PSGI/Http.t new file mode 100644 index 000000000..dc4ea874f --- /dev/null +++ b/t/PSGI/Http.t @@ -0,0 +1,68 @@ +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); + +}; + diff --git a/t/Session/Http.t b/t/Session/Http.t index a97c676e7..a036499a4 100644 --- a/t/Session/Http.t +++ b/t/Session/Http.t @@ -66,11 +66,22 @@ $response->status('200'); $http->setStreamedFile(''); is($http->getStreamedFile, undef, 'set/get StreamedFile: false values return undef, empty string'); -$http->setStreamedFile(0); +$http->setStreamedFile(undef); is($http->getStreamedFile, undef, 'set/get StreamedFile: false values return undef, empty string'); -$http->setStreamedFile('/home/streaming'); -is($http->getStreamedFile, '/home/streaming', 'set/get StreamedFile: set specific location and get it'); +my $actual_file = $session->config->get('uploadsPath') . '/9e/a3/9ea37e148e517d4ae3d6326f691d848f/previous.gif'; # arbitrary file that exactually exists and hopefully will continue for a while +$http->setStreamedFile( $actual_file ); +is($http->getStreamedFile, $actual_file, 'set/get StreamedFile: set specific location and get it'); + +do { + eval { + $http->setStreamedFile( $actual_file . '_but_actually_not_an_actual_file_because_someone_appended_a_bunch_of_bloody_garbage_to_it' ); + }; + my $e = WebGUI::Error->caught("WebGUI::Error::InvalidFile"); + my $errorMessage = $e->error; + ok($errorMessage =~ m/No such file or directory/, "set/get StreamedFile: setting a non-existant file blows stuff up but that's okay because it's handled gracefully" ); +}; + $http->setStreamedFile(''); ####################################################