Skip to content

[API] Ignore If-Modified-Since when If-None-Match is present #329

@RedZapdos123

Description

@RedZapdos123

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:

  1. Run the request with only a matching If-None-Match header.
  2. Run the same request again with the same matching If-None-Match header and an older If-Modified-Since header.
  3. Compare the two responses.
Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions