From 5beb29c4b283705150806e484608ff44c611cd24 Mon Sep 17 00:00:00 2001 From: Robert Rothenberg Date: Thu, 25 Mar 2021 15:48:57 +0000 Subject: [PATCH] Plack::Middleware::ConditionalGET only check if HTTP 200 [Bug Fix] RFC 2616 Sec 14.25 states that: > If the request would normally result in anything other than a > 200 (OK) status, ... the response is exactly the same as for > a normal GET. There is no point in checking the headers if the status code is something else. --- lib/Plack/Middleware/ConditionalGET.pm | 2 +- t/Plack-Middleware/conditionalget.t | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Plack/Middleware/ConditionalGET.pm b/lib/Plack/Middleware/ConditionalGET.pm index 8a9eb5ea5..9bd28f02b 100644 --- a/lib/Plack/Middleware/ConditionalGET.pm +++ b/lib/Plack/Middleware/ConditionalGET.pm @@ -12,7 +12,7 @@ sub call { $self->response_cb($res, sub { my $res = shift; - + return unless $res->[0] == 200; my $h = Plack::Util::headers($res->[1]); # check both ETag and If-Modified-Since, and at least one should exist diff --git a/t/Plack-Middleware/conditionalget.t b/t/Plack-Middleware/conditionalget.t index 483ebf14a..c0038b79e 100644 --- a/t/Plack-Middleware/conditionalget.t +++ b/t/Plack-Middleware/conditionalget.t @@ -20,6 +20,12 @@ my @tests = ( status => 304, headers => [ ETag => $tag ], }, + { + app => sub { [ 404, [ 'ETag' => $tag, 'Content-Type' => 'text/plain' ], [ 'Not Found' ] ] }, + env => { REQUEST_METHOD => "GET", HTTP_IF_NONE_MATCH => $tag }, + status => 404, + headers => [ ETag => $tag, 'Content-Type' => 'text/plain' ], + }, { app => sub { [ 200, [ 'Last-Modified' => $date, 'Content-Type' => 'text/plain' ], [ 'OK' ] ] }, env => { REQUEST_METHOD => "GET", HTTP_IF_MODIFIED_SINCE => $date }, @@ -80,8 +86,3 @@ for my $block (@tests) { is $res->[0], $block->{status}; is_deeply $res->[1], $block->{headers}; } - - - - -