diff options
| author | Leo Lapworth <leo@cuckoo.org> | 2011-04-14 17:29:08 +0100 |
|---|---|---|
| committer | Leo Lapworth <leo@cuckoo.org> | 2011-04-14 17:29:08 +0100 |
| commit | a6d0de3525b158539431baffb4eb80d1e9008f67 (patch) | |
| tree | 5f41b3f300ac3996fb9ef3585f49dbbce23a5226 /t | |
| parent | update README (diff) | |
| download | plack-middleware-etag-a6d0de3525b158539431baffb4eb80d1e9008f67.tar.gz | |
Add check_last_modified_header option - do not add ETag if Last-Modified set
http://code.google.com/speed/page-speed/docs/caching.html#LeverageBrowserCaching
"It is important to specify one of Expires or Cache-Control max-age,
and _one_ of Last-Modified or ETag"
Diffstat (limited to 't')
| -rw-r--r-- | t/02_last_modified.t | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/t/02_last_modified.t b/t/02_last_modified.t new file mode 100644 index 0000000..d14998b --- /dev/null +++ b/t/02_last_modified.t @@ -0,0 +1,60 @@ +use strict; +use warnings; +use Test::More; + +use Digest::SHA; + +use Plack::Test; +use Plack::Builder; +use HTTP::Request::Common; + +my $content = [qw/hello world/]; +my $sha = Digest::SHA->new->add(@$content)->hexdigest; + +my $app = sub { + [ '200', + [ 'Content-Type' => 'text/html', + 'Last-Modified' => 'Wed, 07 Apr 2010 15:07:04 GMT' + ], + $content + ]; +}; + +my $handler = builder { + enable "Plack::Middleware::ETag"; + $app; +}; + +my $handler_with_last_mod = builder { + enable "Plack::Middleware::ETag", check_last_modified_header => 1; + $app; +}; + +# Don't break backwards compat +test_psgi + app => $handler, + client => sub { + my $cb = shift; + { + my $req = GET "http://localhost/"; + my $res = $cb->($req); + ok $res->header('ETag'); + ok $res->header('Last-Modified'); + is $res->header('ETag'), $sha; + } + }; + +# With check_last_modified_header there should be no etag set +test_psgi + app => $handler_with_last_mod, + client => sub { + my $cb = shift; + { + my $req = GET "http://localhost/"; + my $res = $cb->($req); + ok !$res->header('ETag'); + ok $res->header('Last-Modified'); + } + }; + +done_testing; |
