Skip to content

Commit 9e597ea

Browse files
authored
Merge pull request rails#52289 from Shopify/fix-strict-freshness
Check `If-None-Match` before `If-Modified-Since` with strict freshness
2 parents 9f178ad + bdd9f4e commit 9e597ea

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

actionpack/lib/action_dispatch/http/cache.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def etag_matches?(etag)
4444
# Reference: http://tools.ietf.org/html/rfc7232#section-6
4545
def fresh?(response)
4646
if Request.strict_freshness
47-
if if_modified_since
47+
if if_none_match
4848
etag_matches?(response.etag)
49-
elsif if_none_match
49+
elsif if_modified_since
5050
not_modified?(response.last_modified)
5151
else
5252
false

actionpack/test/controller/api/conditional_get_test.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,25 @@ def test_etag_matches
7070
assert_response :not_modified
7171
end
7272

73-
def test_etag_precedence_over_last_modified
73+
def test_strict_freshness_with_etag
74+
with_strict_freshness(true) do
75+
@request.if_none_match = weak_etag([:foo, 123])
76+
77+
get :one
78+
assert_response :not_modified
79+
end
80+
end
81+
82+
def test_strict_freshness_with_last_modified
83+
with_strict_freshness(true) do
84+
@request.if_modified_since = @last_modified
85+
86+
get :one
87+
assert_response :not_modified
88+
end
89+
end
90+
91+
def test_strict_freshness_etag_precedence_over_last_modified
7492
with_strict_freshness(true) do
7593
# Not modified because the etag matches
7694
@request.if_modified_since = 5.years.ago.httpdate

0 commit comments

Comments
 (0)