diff --git a/lib/remote_storage/swift.rb b/lib/remote_storage/swift.rb index 216b7ab..2581ab5 100644 --- a/lib/remote_storage/swift.rb +++ b/lib/remote_storage/swift.rb @@ -75,9 +75,10 @@ module RemoteStorage end def get_directory_listing(user, directory) - # TODO check IF_NONE_MATCH header 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["ETag"] = %Q("#{etag}") diff --git a/spec/swift/app_spec.rb b/spec/swift/app_spec.rb index 877b0f7..9022913 100644 --- a/spec/swift/app_spec.rb +++ b/spec/swift/app_spec.rb @@ -183,6 +183,13 @@ describe "App" do last_response.headers["ETag"].must_equal "\"bla\"" 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 get "/phil/food/"