From 327df973ccdd0def50a4448a3161df8dc76b8a03 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Tue, 7 Jul 2015 11:28:18 -0700 Subject: Fix off-by-one error. When calling the `stat` function on a file, the inode number is stored in the second element (index 1) of the array, not the third (index 2). Instead of getting the inode we were using the mode, which is incorrect. --- lib/Plack/Middleware/ETag.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Plack/Middleware/ETag.pm b/lib/Plack/Middleware/ETag.pm index 22dcc01..86912f4 100644 --- a/lib/Plack/Middleware/ETag.pm +++ b/lib/Plack/Middleware/ETag.pm @@ -35,13 +35,12 @@ sub call { my $file_attr = $self->file_etag || [qw/inode mtime size/]; my @stats = stat $res->[2]; if ( $stats[9] == time - 1 ) { - - # if the file was modified less than one second before the request - # it may be modified in a near future, so we return a weak etag + # if the file was modified less than one second before the request + # it may be modified in a near future, so we return a weak etag $etag = "W/"; } if ( grep {/inode/} @$file_attr ) { - $etag .= ( sprintf "%x", $stats[2] ); + $etag .= ( sprintf "%x", $stats[1] ); } if ( grep {/mtime/} @$file_attr ) { $etag .= "-" if ( $etag && $etag !~ /-$/ ); -- cgit v1.2.3