Replace absolute cache control with ETag
authorDan Scott <dscott@laurentian.ca>
Sun, 2 Apr 2017 23:03:16 +0000 (19:03 -0400)
committerDan Scott <dscott@laurentian.ca>
Sun, 2 Apr 2017 23:03:16 +0000 (19:03 -0400)
Hard-coding no-store / expires: -1 into the handler prevents
the possibility of caching responses, which we might want for
offline mode. We can use the ETag header to get clients to
always try a network request; if they have connectivity, then
the server will always return an updated response.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm

index 6aa1f58..6548edc 100644 (file)
@@ -184,8 +184,7 @@ sub load {
     return $self->redirect_auth unless $self->editor->requestor;
 
     # Don't cache anything requiring auth for security reasons
-    $self->apache->headers_out->add("cache-control" => "no-store, no-cache, must-revalidate");
-    $self->apache->headers_out->add("expires" => "-1");
+    $self->apache->headers_out->add("cache-control" => "no-cache, must-revalidate");
 
     return $self->load_email_record if $path =~ m|opac/record/email|;
 
index da18d7e..65721d2 100644 (file)
@@ -129,11 +129,16 @@ sub handler_guts {
     $vhost_processor_cache{$processor_key} = $tt;
     $ctx->{encode_utf8} = sub {return encode_utf8(shift())};
 
-    unless($tt->process($template, {ctx => $ctx, ENV => \%ENV, l => $text_handler}, $r)) {
+    my $_out = '';
+    unless($tt->process($template, {ctx => $ctx, ENV => \%ENV, l => $text_handler}, \$_out)) {
         $r->log->warn('egweb: template error: ' . $tt->error);
         return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
     }
 
+    my $etag = md5_hex(Encode::encode_utf8($_out);)
+    $r->headers_out->add('Etag' => "\"$etag\"");
+    $r->print($_out);
+
     return Apache2::Const::OK;
 }