fixed HTTP bugs

This commit is contained in:
JT Smith 2004-09-20 19:22:03 +00:00
parent 3248a01b2f
commit 3ce8565a4f
4 changed files with 61 additions and 36 deletions

View file

@ -6,6 +6,10 @@
- Fixed a bug in the URL checker javascript that wouldn't allow for relative
paths.
- bugfix [ 991205 ] 6.0.3 Data Form data field sequence problem (Steven Chan)
- bugfix [ 1028498 ] Problem with page link in navigation
- bugfix [ 1031411 ] FileCache Problem since V6.2.x
- Fixed a problem with HTTP codes being spewed into the page content on codes
other than 200.
6.2.3
- Changed to new POD format.

View file

@ -120,7 +120,6 @@ sub page {
my $output = _processOperations();
if ($output ne "") {
$output = _generatePage($output);
$output = WebGUI::HTTP::getHeader().$output;
} else {
my $useCache = (
$session{form}{op} eq "" &&
@ -154,12 +153,12 @@ sub page {
} else {
$ttl = $session{page}{cacheTimeout};
}
$output = WebGUI::HTTP::getHeader().$output;
$cache->set($output, $ttl) if ($useCache);
$cache->set($output, $ttl) if ($useCache && !WebGUI::HTTP::isRedirect());
WebGUI::PassiveProfiling::addPage(); # add wobjects on page to passive profile log
}
}
WebGUI::Affiliate::grabReferral(); # process affilliate tracking request
$output = WebGUI::HTTP::getHeader().$output;
# This allows an operation or wobject to write directly to the browser.
$output = undef if ($session{page}{empty});
WebGUI::Session::close() unless ($useExistingSession);

View file

@ -34,6 +34,10 @@ use WebGUI::HTTP;
WebGUI::HTTP::setRedirect($url);
WebGUI::HTTP::setCookie($name,$value);
WebGUI::HTTP::setNoHeader($bool);
$mimetype = WebGUI::HTTP::getMimeType();
$code = WebGUI::HTTP::getStatus();
$boolean = WebGUI::HTTP::isRedirect();
=head1 METHODS
@ -53,33 +57,34 @@ Generates an HTTP header.
sub getHeader {
return undef if ($session{http}{noHeader});
my $header;
unless (exists $session{http}{location}) {
unless ($session{http}{charset}) {
$session{http}{charset} = WebGUI::International::getLanguage($session{page}{languageId},"charset") || "ISO-8859-1";
}
unless ($session{http}{mimetype}) {
$session{http}{mimetype} = "text/html";
}
if ($session{setting}{preventProxyCache}) {
$session{http}{expires} = "-1d";
}
$header = $session{cgi}->header(
-type => $session{http}{mimetype},
-charset => $session{http}{charset},
-cookie => $session{http}{cookie},
-status => $session{http}{status},
-attachment => $session{http}{filename},
-expires => $session{http}{expires}
my %params;
if (isRedirect()) {
%params = (
-location => $session{http}{location}
);
} else {
$header = $session{cgi}->header(
-cookie => $session{http}{cookie},
-location => $session{http}{location},
-status => $session{http}{status}
%params = (
-type => $session{http}{mimetype} || "text/html",
-charset => $session{http}{charset} || WebGUI::International::getLanguage($session{page}{languageId},"charset") || "UTF-8"
);
if ($session{setting}{preventProxyCache}) {
$params{"-expires"} = "-1d";
}
if ($session{http}{filename}) {
$params{"-attachment"} => $session{http}{filename};
}
}
return $header;
$params{"-cookie"} = $session{http}{cookie};
if($session{env}{MOD_PERL}) {
my $r = Apache->request;
if(defined($r)) {
$r->custom_response($session{http}{status}, '<!-- '.$session{http}{statusDescription}.' -->' );
$r->status($session{http}{status});
}
} else {
$params{"-status"} = $session{http}{status}.' '.$session{http}{statusDescription};
}
return $session{cgi}->header(%params);
}
@ -105,10 +110,22 @@ Returns the current HTTP status code, if one has been set.
=cut
sub getStatus {
return $session{http}{status} || "200 OK";
return $session{http}{status} || "200";
}
#-------------------------------------------------------------------
=head2 isRedirect ( )
Returns a boolean value indicating whether the current page will redirect to some other location.
=cut
sub isRedirect {
return (getStatus() eq "302");
}
#-------------------------------------------------------------------
=head2 setCookie ( name, value [ , timeToLive ] )
@ -215,24 +232,29 @@ The URL to redirect to.
sub setRedirect {
$session{http}{location} = shift;
setStatus("302 Redirect");
setStatus("302", "Redirect");
}
#-------------------------------------------------------------------
=head2 setStatus ( status )
=head2 setStatus ( code, description )
Sets the HTTP status code.
=head3 status
=head3 code
An HTTP status code. It takes the form of "NNN Message" where NNN is a 3 digit status number and Message is some text explaining the status number.
An HTTP status code. It is a 3 digit status number.
=head3 description
An HTTP status code description. It is a little one line of text that describes the status code.
=cut
sub setStatus {
$session{http}{status} = shift;
$session{http}{statusDescription} = shift;
}
1;

View file

@ -51,7 +51,7 @@ Returns a message stating that this functionality can only be used by administra
=cut
sub adminOnly {
WebGUI::HTTP::setStatus("401 Admin Only");
WebGUI::HTTP::setStatus("401", "Admin Only");
my ($output, $sth, @data);
$output = '<h1>'.WebGUI::International::get(35).'</h1>';
$output .= WebGUI::International::get(36);
@ -68,7 +68,7 @@ Returns a message stating that the user does not have the required privileges to
=cut
sub insufficient {
WebGUI::HTTP::setStatus("401 Insufficient Privileges");
WebGUI::HTTP::setStatus("401", "Insufficient Privileges");
my ($output);
$output = '<h1>'.WebGUI::International::get(37).'</h1>';
$output .= WebGUI::International::get(38);
@ -86,7 +86,7 @@ Returns a message stating that the user does not have the privileges necessary t
=cut
sub noAccess {
WebGUI::HTTP::setStatus("401 No Access");
WebGUI::HTTP::setStatus("401", "No Access");
my ($output);
if ($session{user}{userId} <= 1) {
$output = WebGUI::Operation::Auth::www_auth("init");
@ -107,7 +107,7 @@ Returns a message stating that the user they requested information about is no l
=cut
sub notMember {
WebGUI::HTTP::setStatus("400 Not A Member");
WebGUI::HTTP::setStatus("400", "Not A Member");
my ($output);
$output = '<h1>'.WebGUI::International::get(345).'</h1>';
$output .= WebGUI::International::get(346);
@ -124,7 +124,7 @@ Returns a message stating that the user made a request to delete something that
=cut
sub vitalComponent {
WebGUI::HTTP::setStatus("403 Vital Component");
WebGUI::HTTP::setStatus("403", "Vital Component");
my ($output);
$output = '<h1>'.WebGUI::International::get(40).'</h1>';
$output .= WebGUI::International::get(41);