Check IF_NONE_MATCH header for directory listings

This commit is contained in:
Garret Alfert 2016-01-23 14:29:37 -05:00
parent bec9f7a6cc
commit 15196ca4b9
2 changed files with 9 additions and 1 deletions

View File

@ -75,9 +75,10 @@ module RemoteStorage
end end
def get_directory_listing(user, directory) def get_directory_listing(user, directory)
# TODO check IF_NONE_MATCH header
etag = redis.hget "rs_meta:#{user}:#{directory}/", "etag" etag = redis.hget "rs_meta:#{user}:#{directory}/", "etag"
none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").split(",").map(&:strip)
server.halt 304 if none_match.include? etag
server.headers["Content-Type"] = "application/json" server.headers["Content-Type"] = "application/json"
server.headers["ETag"] = %Q("#{etag}") server.headers["ETag"] = %Q("#{etag}")

View File

@ -183,6 +183,13 @@ describe "App" do
last_response.headers["ETag"].must_equal "\"bla\"" last_response.headers["ETag"].must_equal "\"bla\""
end end
it "responds with 304 when IF_NONE_MATCH header contains the ETag" do
header "If-None-Match", "bla"
get "/phil/food/"
last_response.status.must_equal 304
end
it "contains all items in the directory" do it "contains all items in the directory" do
get "/phil/food/" get "/phil/food/"