Skip to content

Instantly share code, notes, and snippets.

@nihen
Created December 20, 2009 18:09
Show Gist options
  • Save nihen/260590 to your computer and use it in GitHub Desktop.
Save nihen/260590 to your computer and use it in GitHub Desktop.
package Plack::Middleware::LastModified;
use strict;
use parent qw( Plack::Middleware );
use Plack::Util;
use File::stat;
use HTTP::Date;
sub call {
my $self = shift;
my $env = shift;
my $res = $self->app->($env);
$self->response_cb($res, sub {
my $res = shift;
return unless Plack::Util::is_real_fh($res->[2]);
Plack::Util::header_set($res->[1], 'Last-Modified' => HTTP::Date::time2str( stat($res->[2])->mtime ));
});
}
1;
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment