Ignore weak ETAG prefix when comparing MATCH headers

Our metadata only contains the actual ETAG value, so we need
to use only that when comparing it.
This commit is contained in:
Garret Alfert
2018-01-03 21:29:52 +01:00
parent abddec62de
commit 8ffd15bb61
2 changed files with 75 additions and 4 deletions

View File

@@ -52,7 +52,7 @@ module RemoteStorage
set_response_headers(res)
none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").split(",").map(&:strip)
none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").gsub(/^W\//, "").split(",").map(&:strip)
server.halt 304 if none_match.include? %Q("#{res.headers[:etag]}")
return res.body
@@ -71,7 +71,7 @@ module RemoteStorage
server.headers["Content-Type"] = "application/ld+json"
none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").split(",").map(&:strip)
none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").gsub(/^W\//, "").split(",").map(&:strip)
if etag
server.halt 304 if none_match.include? %Q("#{etag}")
@@ -139,7 +139,9 @@ module RemoteStorage
url = url_for_key(user, directory, key)
if required_match = server.env["HTTP_IF_MATCH"]
server.halt 412, "Precondition Failed" unless required_match == %Q("#{existing_metadata["e"]}")
unless required_match.gsub(/^W\//, "") == %Q("#{existing_metadata["e"]}")
server.halt 412, "Precondition Failed"
end
end
if server.env["HTTP_IF_NONE_MATCH"] == "*"
server.halt 412, "Precondition Failed" unless existing_metadata.empty?
@@ -185,7 +187,9 @@ module RemoteStorage
existing_metadata = redis.hgetall "rs:m:#{user}:#{directory}/#{key}"
if required_match = server.env["HTTP_IF_MATCH"]
server.halt 412, "Precondition Failed" unless required_match == %Q("#{existing_metadata["e"]}")
unless required_match.gsub(/^W\//, "") == %Q("#{existing_metadata["e"]}")
server.halt 412, "Precondition Failed"
end
end
begin