diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index 16edd80..88f85fa 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -50,7 +50,8 @@ module RemoteStorage set_object_response_headers(object) - server.halt 304 if server.env["HTTP_IF_NONE_MATCH"] == object.etag + none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").split(",").map(&:strip) + server.halt 304 if none_match.include? object.etag if binary_key = object.meta["binary_key"] object = cs_binary_bucket.files.get(binary_key[0]) @@ -86,7 +87,8 @@ module RemoteStorage set_directory_response_headers(directory_object) - server.halt 304 if server.env["HTTP_IF_NONE_MATCH"] == directory_object.etag + none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").split(",").map(&:strip) + server.halt 304 if none_match.include? directory_object.etag listing = directory_listing(user, directory) diff --git a/spec/directories_spec.rb b/spec/directories_spec.rb index 36670f7..5990e4d 100644 --- a/spec/directories_spec.rb +++ b/spec/directories_spec.rb @@ -129,6 +129,31 @@ describe "Directories" do end end + describe "when If-None-Match header is set with multiple revisions" do + before do + get "/jimmy/tasks/" + + @etag = last_response.headers["ETag"] + end + + it "responds with 'not modified' when it contains the current ETag" do + header "If-None-Match", "DEADBEEF,#{@etag} ,F00BA4" + get "/jimmy/tasks/" + + last_response.status.must_equal 304 + last_response.body.must_be_empty + last_response.headers["ETag"].must_equal @etag + end + + it "responds normally when it does not contain the current ETag" do + header "If-None-Match", "FOO,BAR" + get "/jimmy/tasks/" + + last_response.status.must_equal 200 + last_response.body.wont_be_empty + end + end + context "with sub-directories" do before do get "/jimmy/tasks/" diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index 035383e..8cccac4 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -156,6 +156,25 @@ describe "App with Riak backend" do last_response.body.must_equal "some private text data" end end + + describe "when If-None-Match header is set with multiple revisions" do + it "responds with 'not modified' when it contains the current ETag" do + header "If-None-Match", "DEADBEEF,#{@etag},F00BA4" + get "/jimmy/documents/foo" + + last_response.status.must_equal 304 + last_response.body.must_be_empty + last_response.headers["ETag"].must_equal @etag + end + + it "responds normally when it does not contain the current ETag" do + header "If-None-Match", "FOO,BAR" + get "/jimmy/documents/foo" + + last_response.status.must_equal 200 + last_response.body.must_equal "some private text data" + end + end end describe "GET nonexisting key" do