summary refs log tree commit diff
path: root/pkgs/development/perl-modules/catalyst-plugin-static-simple-etag.patch
blob: 06207a8b7334b238b74dc51f71bd966cd0fbbad0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Send an ETag header, and honour the If-None-Match request header

diff -ru -x '*~' Catalyst-Plugin-Static-Simple-0.30-orig/lib/Catalyst/Plugin/Static/Simple.pm Catalyst-Plugin-Static-Simple-0.30/lib/Catalyst/Plugin/Static/Simple.pm
--- Catalyst-Plugin-Static-Simple-0.30-orig/lib/Catalyst/Plugin/Static/Simple.pm	2012-05-04 18:49:30.000000000 +0200
+++ Catalyst-Plugin-Static-Simple-0.30/lib/Catalyst/Plugin/Static/Simple.pm	2013-02-25 22:57:18.667150181 +0100
@@ -187,16 +187,27 @@
     my $type      = $c->_ext_to_type( $full_path );
     my $stat      = stat $full_path;
 
-    $c->res->headers->content_type( $type );
-    $c->res->headers->content_length( $stat->size );
-    $c->res->headers->last_modified( $stat->mtime );
     # Tell Firefox & friends its OK to cache, even over SSL:
-    $c->res->headers->header('Cache-control' => 'public');
+    #$c->res->headers->header('Cache-control' => 'public');
+
+    $c->res->headers->last_modified( $stat->mtime );
     # Optionally, set a fixed expiry time:
     if ($config->{expires}) {
         $c->res->headers->expires(time() + $config->{expires});
     }
 
+    if ($config->{send_etag}) {
+        my $etag = '"' . $stat->mtime . '-' . $stat->ino . '-'. $stat->size . '"';
+        $c->res->headers->header('ETag' => $etag);
+        if (($c->req->header('If-None-Match') // "") eq $etag) {
+            $c->res->status(304);
+            return 1;
+        }
+    }
+
+    $c->res->headers->content_type( $type );
+    $c->res->headers->content_length( $stat->size );
+
     my $fh = IO::File->new( $full_path, 'r' );
     if ( defined $fh ) {
         binmode $fh;