Move ifModifiedSince into WebGUI::Session::Request
This commit is contained in:
parent
995b04e7de
commit
e7fcf33a4d
5 changed files with 40 additions and 62 deletions
|
|
@ -69,7 +69,7 @@ sub dispatch {
|
|||
WebGUI::PassiveAnalytics::Logging::log($session, $asset);
|
||||
# display from cache if page hasn't been modified.
|
||||
if ($session->user->isVisitor
|
||||
&& !$session->http->ifModifiedSince($asset->getContentLastModified, $session->setting->get('maxCacheTimeout'))) {
|
||||
&& !$session->request->ifModifiedSince($asset->getContentLastModified, $session->setting->get('maxCacheTimeout'))) {
|
||||
$session->response->status("304");
|
||||
$session->http->sendHeader;
|
||||
return "chunked";
|
||||
|
|
|
|||
|
|
@ -121,40 +121,6 @@ sub getStreamedFile {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 ifModifiedSince ( epoch [, maxCacheTimeout] )
|
||||
|
||||
Returns 1 if the epoch is greater than the modified date check.
|
||||
|
||||
=head3 epoch
|
||||
|
||||
The date that the requested content was last modified in epoch format.
|
||||
|
||||
=head3 maxCacheTimeout
|
||||
|
||||
A modifier to the epoch, that allows us to set a maximum timeout where content will appear to
|
||||
have changed and a new page request will be allowed to be processed.
|
||||
|
||||
=cut
|
||||
|
||||
sub ifModifiedSince {
|
||||
my $self = shift;
|
||||
my $epoch = shift;
|
||||
my $maxCacheTimeout = shift;
|
||||
my $modified = $self->session->request->header('If-Modified-Since');
|
||||
return 1 if ($modified eq "");
|
||||
$modified = HTTP::Date::str2time($modified);
|
||||
##Implement a step function that increments the epoch time in integer multiples of
|
||||
##the maximum cache time. Used to handle the case where layouts containing macros
|
||||
##(like assetproxied Navigations) can be periodically updated.
|
||||
if ($maxCacheTimeout) {
|
||||
my $delta = time() - $epoch;
|
||||
$epoch += $delta - ($delta % $maxCacheTimeout);
|
||||
}
|
||||
return ($epoch > $modified);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 isRedirect ( )
|
||||
|
|
|
|||
|
|
@ -76,6 +76,40 @@ sub callerIsSearchSite {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 ifModifiedSince ( epoch [, maxCacheTimeout] )
|
||||
|
||||
Returns 1 if the epoch is greater than the modified date check.
|
||||
|
||||
=head3 epoch
|
||||
|
||||
The date that the requested content was last modified in epoch format.
|
||||
|
||||
=head3 maxCacheTimeout
|
||||
|
||||
A modifier to the epoch, that allows us to set a maximum timeout where content will appear to
|
||||
have changed and a new page request will be allowed to be processed.
|
||||
|
||||
=cut
|
||||
|
||||
sub ifModifiedSince {
|
||||
my $self = shift;
|
||||
my $epoch = shift;
|
||||
my $maxCacheTimeout = shift;
|
||||
my $modified = $self->header('If-Modified-Since');
|
||||
return 1 if ($modified eq "");
|
||||
$modified = HTTP::Date::str2time($modified);
|
||||
##Implement a step function that increments the epoch time in integer multiples of
|
||||
##the maximum cache time. Used to handle the case where layouts containing macros
|
||||
##(like assetproxied Navigations) can be periodically updated.
|
||||
if ($maxCacheTimeout) {
|
||||
my $delta = time() - $epoch;
|
||||
$epoch += $delta - ($delta % $maxCacheTimeout);
|
||||
}
|
||||
return ($epoch > $modified);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new_response ()
|
||||
|
||||
Creates a new L<WebGUI::Session::Response> object.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue