Set headers from the Redis metadata on a GET that results in a 304

Also add specs to check for the response headers
This commit is contained in:
Greg Karékinian 2018-04-16 17:23:53 +02:00
parent f083022e6d
commit 7bd45543f6
3 changed files with 14 additions and 2 deletions

View File

@ -49,8 +49,12 @@ module RemoteStorage
none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").split(",")
.map(&:strip)
.map { |s| s.gsub(/^"?W\//, "") }
etag = redis.hget redis_metadata_object_key(user, directory, key), "e"
server.halt 304 if none_match.include? %Q("#{etag}")
existing_metadata = redis.hgetall redis_metadata_object_key(user, directory, key)
if none_match.include? %Q("#{existing_metadata["e"]}")
server.headers["ETag"] = %Q("#{existing_metadata["e"]}")
server.headers["Last-Modified"] = Time.at(existing_metadata["m"].to_i / 1000).httpdate
server.halt 304
end
url = url_for_key(user, directory, key)

View File

@ -687,6 +687,8 @@ describe "App" do
get "/phil/food/aguacate"
last_response.status.must_equal 304
last_response.headers["ETag"].must_equal "\"0815etag\""
last_response.headers["Last-Modified"].must_equal "Fri, 04 Mar 2016 12:20:18 GMT"
end
it "responds with 304 when IF_NONE_MATCH header contains weak ETAG matching the current ETag" do
@ -695,6 +697,8 @@ describe "App" do
get "/phil/food/aguacate"
last_response.status.must_equal 304
last_response.headers["ETag"].must_equal "\"0815etag\""
last_response.headers["Last-Modified"].must_equal "Fri, 04 Mar 2016 12:20:18 GMT"
end
end

View File

@ -645,6 +645,8 @@ describe "App" do
get "/phil/food/aguacate"
last_response.status.must_equal 304
last_response.headers["ETag"].must_equal "\"0815etag\""
last_response.headers["Last-Modified"].must_equal "Fri, 04 Mar 2016 12:20:18 GMT"
end
it "responds with 304 when IF_NONE_MATCH header contains weak ETAG matching the current ETag" do
@ -653,6 +655,8 @@ describe "App" do
get "/phil/food/aguacate"
last_response.status.must_equal 304
last_response.headers["ETag"].must_equal "\"0815etag\""
last_response.headers["Last-Modified"].must_equal "Fri, 04 Mar 2016 12:20:18 GMT"
end
end