Description:
Verified on latest main at aa15f81a245fbc9c031fcb9c6e03fcffb275c7bd.
Rage::Request#fresh? combines If-None-Match and If-Modified-Since with a logical &&.
When If-None-Match matches but If-Modified-Since is older than the resource, Rage renders 200 OK and returns the response body.
For requests that include If-None-Match, If-Modified-Since should be ignored.
Minimal reproducible example:
require "digest/sha1"
require "time"
require "rage/all"
class TestController < RageController::API
def show
return unless stale?(etag: "123", last_modified: Time.utc(2023, 12, 1))
render plain: "body"
end
end
handler = TestController.__register_action(:show)
matching_etag = %(W/"#{Digest::SHA1.hexdigest("123")}")
pp TestController.new({ "HTTP_IF_NONE_MATCH" => matching_etag }, {}).public_send(handler)
pp TestController.new({
"HTTP_IF_NONE_MATCH" => matching_etag,
"HTTP_IF_MODIFIED_SINCE" => Time.utc(2023, 11, 15).httpdate
}, {}).public_send(handler)
Steps to reproduce:
- Run the request with only a matching
If-None-Match header.
- Run the same request again with the same matching
If-None-Match header and an older If-Modified-Since header.
- Compare the two responses.
Actual behavior:
- With only matching
If-None-Match, Rage returns 304 Not Modified.
- With the same matching
If-None-Match plus older If-Modified-Since, Rage returns 200 OK and renders the body.
- Output on latest
main:
{:only_if_none_match=>
[304,
{"content-type"=>"application/json; charset=utf-8",
"etag"=>"W/\"40bd001563085fc35165329ea1ff5c5ecbdbbeef\"",
"last-modified"=>"Fri, 01 Dec 2023 00:00:00 GMT"},
[]],
:if_none_match_and_older_if_modified_since=>
[200,
{"content-type"=>"text/plain; charset=utf-8",
"etag"=>"W/\"40bd001563085fc35165329ea1ff5c5ecbdbbeef\"",
"last-modified"=>"Fri, 01 Dec 2023 00:00:00 GMT"},
["body"]]}
Expected behavior:
- When
If-None-Match is present and matches, Rage should ignore If-Modified-Since.
- Both requests above should return
304 Not Modified.
Description:
Verified on latest
mainataa15f81a245fbc9c031fcb9c6e03fcffb275c7bd.Rage::Request#fresh?combinesIf-None-MatchandIf-Modified-Sincewith a logical&&.When
If-None-Matchmatches butIf-Modified-Sinceis older than the resource, Rage renders200 OKand returns the response body.For requests that include
If-None-Match,If-Modified-Sinceshould be ignored.Minimal reproducible example:
Steps to reproduce:
If-None-Matchheader.If-None-Matchheader and an olderIf-Modified-Sinceheader.Actual behavior:
If-None-Match, Rage returns304 Not Modified.If-None-Matchplus olderIf-Modified-Since, Rage returns200 OKand renders the body.main:Expected behavior:
If-None-Matchis present and matches, Rage should ignoreIf-Modified-Since.304 Not Modified.