diff --git a/lib/WebGUI/Session/Http.pm b/lib/WebGUI/Session/Http.pm index 6a6b6fa0b..5330a04ee 100644 --- a/lib/WebGUI/Session/Http.pm +++ b/lib/WebGUI/Session/Http.pm @@ -36,6 +36,7 @@ This package allows the manipulation of HTTP protocol information. $cookies = $http->getCookies(); $mimetype = $http->getMimeType(); $code = $http->getStatus(); + ($code, $description) = $http->getStatus(); $boolean = $http->isRedirect(); $http->setCookie($name,$value); @@ -105,14 +106,19 @@ sub getMimeType { =head2 getStatus ( ) { -Returns the current HTTP status code, if one has been set. +Returns the current HTTP status code and description. When called in scalar +context, returns only the status code. When called in list context, returns +the status and description. If no code has been set, the code returned will be 200. +If no description has been set, the internal description will be set to "OK" and +"OK" will be returned. =cut sub getStatus { my $self = shift; $self->{_http}{statusDescription} = $self->{_http}{statusDescription} || "OK"; - return $self->{_http}{status} || "200"; + my $status = $self->{_http}{status} || "200"; + return wantarray ? ( $status, $self->{_http}{statusDescription} ) : $status; } diff --git a/t/Session/Http.t b/t/Session/Http.t new file mode 100644 index 000000000..6c72cc7b3 --- /dev/null +++ b/t/Session/Http.t @@ -0,0 +1,53 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2006 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; +use WebGUI::Session; + +use Test::More; # increment this value for each test you create + +my $num_tests = 8; + +plan tests => $num_tests; + +my $session = WebGUI::Test->session; + +# put your tests here + +my $http = $session->http; + +isa_ok($http, 'WebGUI::Session::Http', 'session has correct object type'); + +$http->setStatus('123'); + +is($http->getStatus, '123', 'getStatus: returns correct code in scalar context'); + +my ($status, $description) = $http->getStatus; +is($status, '123', 'getStatus: returns correct code'); +is($description, 'OK', 'getStatus: default description returned'); + +$http->setStatus(''); + +($status, $description) = $http->getStatus; +is($status, '200', 'getStatus: returns default code'); +is($description, 'OK', 'getStatus: default description returned'); + +$http->setStatus('', 'packets are great'); + +($status, $description) = $http->getStatus; +is($status, '200', 'getStatus: returns default code'); +is($description, 'packets are great', 'getStatus: default description returned'); + +END { +}