Remove getRedirectLocation and setRedirectLocation from Session::Http

This commit is contained in:
Colin Kuskie 2010-11-22 09:28:14 -08:00
parent 8b6bbdb9f7
commit 995b04e7de
8 changed files with 33 additions and 51 deletions

View file

@ -312,3 +312,14 @@ the header for the Content-Dispostion, then set the content type.
OLD: $session->http->setFilename($filename); OLD: $session->http->setFilename($filename);
NEW: $session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$filename.'"'); NEW: $session->response->header( 'Content-Disposition' => qq{attachment; filename="}.$filename.'"');
$session->response->content_type('application/octet-stream'); $session->response->content_type('application/octet-stream');
getRedirectLocation and setRedirectLocation have been removed. These methods were not
used outside of WebGUI::Session::Http, but were designed for object encapsulation
inside the object. If you need to directly set or access the redirect location,
use the location mutator in the WebGUI::Response object in the session.
OLD: $session->http->setRedirectLocation($url);
NEW: $session->response->location($url);
OLD: $session->http->getRedirectLocation();
NEW: $session->response->location();

View file

@ -107,20 +107,6 @@ sub getNoHeader {
return $self->{_http}{noHeader}; return $self->{_http}{noHeader};
} }
#-------------------------------------------------------------------
=head2 getRedirectLocation ( )
Return the location that was set via setRedirect
=cut
sub getRedirectLocation {
my $self = shift;
return $self->{_http}{location};
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getStreamedFile ( ) { =head2 getStreamedFile ( ) {
@ -229,9 +215,7 @@ sub sendHeader {
$self->setNoHeader(1); $self->setNoHeader(1);
my %params; my %params;
if ($self->isRedirect()) { if (!$self->isRedirect()) {
$response->header(Location => $self->getRedirectLocation);
} else {
my $cacheControl = $self->getCacheControl; my $cacheControl = $self->getCacheControl;
my $date = ($userId eq "1") ? HTTP::Date::time2str($self->getLastModified) : HTTP::Date::time2str(); my $date = ($userId eq "1") ? HTTP::Date::time2str($self->getLastModified) : HTTP::Date::time2str();
# under these circumstances, don't allow caching # under these circumstances, don't allow caching
@ -407,25 +391,12 @@ sub setRedirect {
my @params = $self->session->form->param; my @params = $self->session->form->param;
return undef if ($url eq $self->session->url->page() && scalar(@params) < 1); # prevent redirecting to self 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->log->info("Redirecting to $url");
$self->setRedirectLocation($url); $self->session->response->location($url);
$self->session->response->status($type); $self->session->response->status($type);
$self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$url}); $self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$url});
} }
#-------------------------------------------------------------------
=head2 setRedirectLocation ( url )
Sets the HTTP redirect URL.
=cut
sub setRedirectLocation {
my $self = shift;
$self->{_http}{location} = shift;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 setStreamedFile ( ) { =head2 setStreamedFile ( ) {

View file

@ -859,26 +859,26 @@ is $trashedAsset->get('state'), 'trash', 'checkView setup: trashed an asset'
is $clippedAsset->get('state'), 'clipboard', '... clipped an asset'; is $clippedAsset->get('state'), 'clipboard', '... clipped an asset';
$session->switchAdminOff; $session->switchAdminOff;
$session->http->setRedirectLocation(''); $session->response->location('');
$session->response->status(200, 'OK'); $session->response->status(200, 'OK');
$trashedAsset->checkView(); $trashedAsset->checkView();
is $session->response->status, 410, '... status set to 410 for trashed asset'; is $session->response->status, 410, '... status set to 410 for trashed asset';
is $session->http->getRedirectLocation, '', '... no redirect set'; is $session->response->location, '', '... no redirect set';
$session->response->status(200, 'OK'); $session->response->status(200, 'OK');
$clippedAsset->checkView(); $clippedAsset->checkView();
is $session->response->status, 410, '... status set to 410 for cut asset'; is $session->response->status, 410, '... status set to 410 for cut asset';
is $session->http->getRedirectLocation, '', '... no redirect set'; is $session->response->location, '', '... no redirect set';
$session->switchAdminOn; $session->switchAdminOn;
$session->response->status(200, 'OK'); $session->response->status(200, 'OK');
is $trashedAsset->checkView(), 'chunked', '... returns "chunked" when admin is on for trashed asset'; is $trashedAsset->checkView(), 'chunked', '... returns "chunked" when admin is on for trashed asset';
is $session->http->getRedirectLocation, $trashedAsset->getUrl('func=manageTrash'), '... trashed asset sets redirect to manageTrash'; is $session->response->location, $trashedAsset->getUrl('func=manageTrash'), '... trashed asset sets redirect to manageTrash';
$session->http->setRedirectLocation(''); $session->response->location('');
is $clippedAsset->checkView(), 'chunked', 'checkView: returns "chunked" when admin is on for cut asset'; is $clippedAsset->checkView(), 'chunked', 'checkView: returns "chunked" when admin is on for cut asset';
is $session->http->getRedirectLocation, $clippedAsset->getUrl('func=manageClipboard'), '... cut asset sets redirect to manageClipboard'; is $session->response->location, $clippedAsset->getUrl('func=manageClipboard'), '... cut asset sets redirect to manageClipboard';
##Return an array of hashrefs. Each hashref describes a test ##Return an array of hashrefs. Each hashref describes a test

View file

@ -132,9 +132,9 @@ is( $newRev->getStorageLocation->getFileContentsAsScalar('.wgaccess'), undef, "w
$session->config->set('enableStreamingUploads', '0'); $session->config->set('enableStreamingUploads', '0');
$asset->www_view; $asset->www_view;
is($session->http->getRedirectLocation, $storage->getUrl('someScalarFile.txt'), 'www_view: sets a redirect'); is($session->response->location, $storage->getUrl('someScalarFile.txt'), 'www_view: sets a redirect');
$session->config->set('enableStreamingUploads', '1'); $session->config->set('enableStreamingUploads', '1');
$session->http->setRedirectLocation(''); $session->response->location('');
$asset->www_view; $asset->www_view;
is($session->http->getRedirectLocation, '', '... redirect not set when enableStreamingUploads is set'); is($session->response->location, '', '... redirect not set when enableStreamingUploads is set');

View file

@ -64,7 +64,7 @@ WebGUI::Test->addToCleanup(sub {
}); });
is( is(
$createAccountSession->http->getRedirectLocation, 'REDIRECT_URL', $createAccountSession->response->location, 'REDIRECT_URL',
"returnUrl field is used to set redirect after createAccountSave", "returnUrl field is used to set redirect after createAccountSave",
); );
@ -83,7 +83,7 @@ $session->setting->set('showMessageOnLogin', 0);
$output = $auth->login; $output = $auth->login;
is( is(
$loginSession->http->getRedirectLocation, 'REDIRECT_LOGIN_URL', $loginSession->response->location, 'REDIRECT_LOGIN_URL',
"returnUrl field is used to set redirect after login", "returnUrl field is used to set redirect after login",
); );
is $output, undef, 'login returns undef when showMessageOnLogin is false'; is $output, undef, 'login returns undef when showMessageOnLogin is false';

View file

@ -68,7 +68,7 @@ isa_ok( $nt, 'Net::Twitter' );
is( $auth->www_login, "redirect", "www_login always returns redirect" ); is( $auth->www_login, "redirect", "www_login always returns redirect" );
ok( $session->scratch->get('AuthTwitterToken'), 'auth token gets set to scratch' ); ok( $session->scratch->get('AuthTwitterToken'), 'auth token gets set to scratch' );
ok( $session->scratch->get('AuthTwitterTokenSecret'), 'auth token secret gets set to scratch' ); ok( $session->scratch->get('AuthTwitterTokenSecret'), 'auth token secret gets set to scratch' );
like( $session->http->getRedirectLocation, qr/twitter[.]com/, "redirect to twitter.com" ); like( $session->response->location, qr/twitter[.]com/, "redirect to twitter.com" );
# www_callback # www_callback
# I have no idea how to test this... # I have no idea how to test this...

View file

@ -20,8 +20,6 @@ use Data::Dumper;
use Test::More; # increment this value for each test you create use Test::More; # increment this value for each test you create
use Test::Deep; use Test::Deep;
plan tests => 40;
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
my $http = $session->http; my $http = $session->http;
@ -100,7 +98,7 @@ $http->setCacheControl(undef);
#################################################### ####################################################
# #
# setRedirect, getRedirectLocation # setRedirect
# #
#################################################### ####################################################
@ -108,7 +106,7 @@ $session->request->uri('/here/later');
$http->setRedirect('/here/now'); $http->setRedirect('/here/now');
is($response->status, 302, 'setRedirect: sets HTTP status'); is($response->status, 302, 'setRedirect: sets HTTP status');
is($http->getRedirectLocation, '/here/now', 'setRedirect: redirect location'); is($response->location, '/here/now', 'setRedirect: redirect location');
$session->style->useEmptyStyle(1); $session->style->useEmptyStyle(1);
my $styled = $session->style->generateAdditionalHeadTags(); my $styled = $session->style->generateAdditionalHeadTags();
@ -414,6 +412,8 @@ is($http->sendHeader, undef, 'sendHeader returns undef when no request object is
ok $session->http->ifModifiedSince(WebGUI::Test->webguiBirthday - 5, 3600), '... epoch check, made true by maxCacheTimeout'; ok $session->http->ifModifiedSince(WebGUI::Test->webguiBirthday - 5, 3600), '... epoch check, made true by maxCacheTimeout';
} }
done_testing;
#################################################### ####################################################
# #
# Utility functions # Utility functions

View file

@ -447,7 +447,7 @@ ok( ! $session->url->forceSecureConnection('/test/url'), 'all conditions must be
##Validate the HTTP object state before we start ##Validate the HTTP object state before we start
$session->response->status('200'); $session->response->status('200');
is($session->response->status, 200, 'http status is okay, 200'); is($session->response->status, 200, 'http status is okay, 200');
is($session->http->getRedirectLocation, undef, 'redirect location is empty'); is($session->response->location, undef, 'redirect location is empty');
$env->{'psgi.url_scheme'} = "http"; $env->{'psgi.url_scheme'} = "http";
@ -456,14 +456,14 @@ $secureUrl =~ s/http:/https:/;
ok($session->url->forceSecureConnection('/foo/bar/baz/buz'), 'forced secure connection'); ok($session->url->forceSecureConnection('/foo/bar/baz/buz'), 'forced secure connection');
is($session->response->status, 302, 'http status set to redirect, 302'); is($session->response->status, 302, 'http status set to redirect, 302');
is($session->http->getRedirectLocation, $secureUrl, 'redirect location set to proper passed in URL with SSL and sitename added'); is($session->response->location, $secureUrl, 'redirect location set to proper passed in URL with SSL and sitename added');
$session->response->status('200', 'OK'); $session->response->status('200', 'OK');
$session->http->setRedirectLocation(undef); $session->response->location(undef);
$secureUrl = $session->url->getSiteURL . $session->url->page(); $secureUrl = $session->url->getSiteURL . $session->url->page();
$secureUrl =~ s/http:/https:/; $secureUrl =~ s/http:/https:/;
ok($session->url->forceSecureConnection(), 'forced secure connection with no url param'); ok($session->url->forceSecureConnection(), 'forced secure connection with no url param');
ok($session->http->isRedirect, '... and redirect status code was set'); ok($session->http->isRedirect, '... and redirect status code was set');
is($session->http->getRedirectLocation, $secureUrl, '... and redirect status code was set'); is($session->response->location, $secureUrl, '... and redirect status code was set');