Also use content checksum for ETag calculation
Timestamp is not enough, as it might be the same for two consequent PUTs.
This commit is contained in:
parent
8bcb8bf337
commit
5378826c6a
@ -156,7 +156,7 @@ module RemoteStorage
|
|||||||
|
|
||||||
if update_metadata_object(user, directory, key, metadata)
|
if update_metadata_object(user, directory, key, metadata)
|
||||||
if metadata_changed?(existing_metadata, metadata)
|
if metadata_changed?(existing_metadata, metadata)
|
||||||
update_dir_objects(user, directory, timestamp)
|
update_dir_objects(user, directory, timestamp, checksum_for(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
server.headers["ETag"] = %Q("#{res.headers[:etag]}")
|
server.headers["ETag"] = %Q("#{res.headers[:etag]}")
|
||||||
@ -166,6 +166,10 @@ module RemoteStorage
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def checksum_for(data)
|
||||||
|
Digest::MD5.hexdigest(data)
|
||||||
|
end
|
||||||
|
|
||||||
def delete_data(user, directory, key)
|
def delete_data(user, directory, key)
|
||||||
url = url_for_key(user, directory, key)
|
url = url_for_key(user, directory, key)
|
||||||
|
|
||||||
@ -316,9 +320,9 @@ module RemoteStorage
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_dir_objects(user, directory, timestamp)
|
def update_dir_objects(user, directory, timestamp, checksum)
|
||||||
parent_directories_for(directory).each do |dir|
|
parent_directories_for(directory).each do |dir|
|
||||||
etag = etag_for(dir, timestamp)
|
etag = etag_for(dir, timestamp, checksum)
|
||||||
|
|
||||||
key = "rs:m:#{user}:#{dir}/"
|
key = "rs:m:#{user}:#{dir}/"
|
||||||
metadata = {e: etag, m: timestamp}
|
metadata = {e: etag, m: timestamp}
|
||||||
|
@ -301,11 +301,11 @@ describe "App" do
|
|||||||
get "/phil/food/"
|
get "/phil/food/"
|
||||||
|
|
||||||
last_response.status.must_equal 200
|
last_response.status.must_equal 200
|
||||||
last_response.headers["ETag"].must_equal "\"a693babe4b4027de2340b4f1c362d2c8\""
|
last_response.headers["ETag"].must_equal "\"f9f85fbf5aa1fa378fd79ac8aa0a457d\""
|
||||||
end
|
end
|
||||||
|
|
||||||
it "responds with 304 when IF_NONE_MATCH header contains the ETag" do
|
it "responds with 304 when IF_NONE_MATCH header contains the ETag" do
|
||||||
header "If-None-Match", "\"a693babe4b4027de2340b4f1c362d2c8\""
|
header "If-None-Match", "\"f9f85fbf5aa1fa378fd79ac8aa0a457d\""
|
||||||
get "/phil/food/"
|
get "/phil/food/"
|
||||||
|
|
||||||
last_response.status.must_equal 304
|
last_response.status.must_equal 304
|
||||||
@ -328,7 +328,7 @@ describe "App" do
|
|||||||
content["items"]["camaron"]["Content-Length"].must_equal 5
|
content["items"]["camaron"]["Content-Length"].must_equal 5
|
||||||
content["items"]["camaron"]["ETag"].must_equal "bla"
|
content["items"]["camaron"]["ETag"].must_equal "bla"
|
||||||
content["items"]["desunyos/"].wont_be_nil
|
content["items"]["desunyos/"].wont_be_nil
|
||||||
content["items"]["desunyos/"]["ETag"].must_equal "5e17228c28f15521416812ecac6f718e"
|
content["items"]["desunyos/"]["ETag"].must_equal "926233ce4a147a5b679e0ddf665517dd"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "contains all items in the root directory" do
|
it "contains all items in the root directory" do
|
||||||
@ -339,7 +339,7 @@ describe "App" do
|
|||||||
|
|
||||||
content = JSON.parse(last_response.body)
|
content = JSON.parse(last_response.body)
|
||||||
content["items"]["food/"].wont_be_nil
|
content["items"]["food/"].wont_be_nil
|
||||||
content["items"]["food/"]["ETag"].must_equal "a693babe4b4027de2340b4f1c362d2c8"
|
content["items"]["food/"]["ETag"].must_equal "f9f85fbf5aa1fa378fd79ac8aa0a457d"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user