summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2011-04-19 11:47:54 +0200
committerfranck cuny <franck@lumberjaph.net>2011-04-19 11:47:54 +0200
commit89dcd4d2b50bea9323f913d83d32cc24fb93d2a2 (patch)
tree036c1fd9f251af47387c06ca9da5b2b3b77fb0e3 /t
parentupdate README (diff)
parentUpdate README as well (diff)
downloadplack-middleware-etag-89dcd4d2b50bea9323f913d83d32cc24fb93d2a2.tar.gz
Merge branch 'review/leo'
* review/leo: Update README as well Add check_last_modified_header option - do not add ETag if Last-Modified set
Diffstat (limited to 't')
-rw-r--r--t/02_last_modified.t60
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;