some http header changes
This commit is contained in:
parent
4a3dab3ddb
commit
e8c073b9df
23 changed files with 206 additions and 54 deletions
|
|
@ -190,7 +190,7 @@ sub fatal {
|
|||
Apache2::RequestUtil->request->content_type('text/html') if ($self->session->request);
|
||||
$self->getLogger->fatal($message);
|
||||
$self->getLogger->debug("Stack trace for FATAL ".$message."\n".$self->getStackTrace());
|
||||
$self->session->http->getHeader if ($self->session->request);
|
||||
$self->session->http->sendHeader if ($self->session->request);
|
||||
unless ($self->canShowDebug()) {
|
||||
#NOTE: You can't internationalize this because with some types of errors that would cause an infinite loop.
|
||||
$self->session->output->print("<h1>Problem With Request</h1>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package WebGUI::Session::Http;
|
|||
use strict;
|
||||
use Apache2::Cookie;
|
||||
use APR::Request::Apache2;
|
||||
use HTTP::Date;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -33,8 +34,9 @@ This package allows the manipulation of HTTP protocol information.
|
|||
|
||||
my $http = WebGUI::Session::Http->new($session);
|
||||
|
||||
$http->sendHeader();
|
||||
|
||||
$cookies = $http->getCookies();
|
||||
$header = $http->getHeader();
|
||||
$mimetype = $http->getMimeType();
|
||||
$code = $http->getStatus();
|
||||
$boolean = $http->isRedirect();
|
||||
|
|
@ -87,37 +89,6 @@ sub getCookies {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getHeader ( )
|
||||
|
||||
Generates an HTTP header.
|
||||
|
||||
=cut
|
||||
|
||||
sub getHeader {
|
||||
my $self = shift;
|
||||
return undef if ($self->{_http}{noHeader});
|
||||
return undef unless $self->session->request;
|
||||
my %params;
|
||||
if ($self->isRedirect()) {
|
||||
$self->session->request->headers_out->set(Location => $self->{_http}{location});
|
||||
$self->session->request->status(301);
|
||||
} else {
|
||||
$self->session->request->content_type($self->{_http}{mimetype} || "text/html");
|
||||
if ($self->session->setting->get("preventProxyCache")) {
|
||||
$self->session->request->headers_out->set(Expires => "-1d");
|
||||
}
|
||||
if ($self->{_http}{filename}) {
|
||||
$self->session->request->headers_out->set('Content-Disposition' => qq!attachment; filename="$self->{_http}{filename}"!);
|
||||
}
|
||||
}
|
||||
#$params{"-cookie"} = $self->{_http}{cookie};
|
||||
$self->session->request->status_line($self->getStatus().' '.$self->{_http}{statusDescription});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getMimeType ( )
|
||||
|
|
@ -180,6 +151,36 @@ sub new {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 sendHeader ( )
|
||||
|
||||
Generates and sends HTTP headers.
|
||||
|
||||
=cut
|
||||
|
||||
sub sendHeader {
|
||||
my $self = shift;
|
||||
return undef if ($self->{_http}{noHeader});
|
||||
return undef unless $self->session->request;
|
||||
my %params;
|
||||
if ($self->isRedirect()) {
|
||||
$self->session->request->headers_out->set(Location => $self->{_http}{location});
|
||||
$self->session->request->status(301);
|
||||
} else {
|
||||
$self->session->request->content_type($self->{_http}{mimetype} || "text/html");
|
||||
if ($self->session->setting->get("preventProxyCache")) {
|
||||
$self->session->request->headers_out->set(Expires => "-1d");
|
||||
}
|
||||
if ($self->{_http}{filename}) {
|
||||
$self->session->request->headers_out->set('Content-Disposition' => qq!attachment; filename="$self->{_http}{filename}"!);
|
||||
}
|
||||
}
|
||||
$self->session->request->status_line($self->getStatus().' '.$self->{_http}{statusDescription});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
|
@ -195,6 +196,33 @@ sub session {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=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;
|
||||
my $request = $self->session->request;
|
||||
if (defined $request) {
|
||||
if ($timeout eq "none" || $self->session->setting->get("preventProxyCache")) {
|
||||
$self->session->request->no_cache(1);
|
||||
} elsif ($request->protocol =~ /(\d\.\d)/ && $1 >= 1.1){
|
||||
$request->header_out('Cache-Control', "max-age=" . $timeout);
|
||||
} else {
|
||||
$request->header_out('Expires', HTTP::Date::time2str(time + $self->get("cacheTimeout")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setCookie ( name, value [ , timeToLive ] )
|
||||
|
||||
Sends a cookie to the browser.
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ if ($self->session->user->isInGroup(2)) {
|
|||
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate, max-age=0" />
|
||||
<meta http-equiv="Expires" content="0" />
|
||||
';
|
||||
$self->session->request->no_cache(1) if ($self->session->request);
|
||||
$self->session->http->setCacheControl("none");
|
||||
}
|
||||
my $style = WebGUI::Asset::Template->new($self->session,$templateId);
|
||||
my $output;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue