diff --git a/lib/remote_storage/rest_provider.rb b/lib/remote_storage/rest_provider.rb index 9034533..37ebe10 100644 --- a/lib/remote_storage/rest_provider.rb +++ b/lib/remote_storage/rest_provider.rb @@ -49,8 +49,12 @@ module RemoteStorage none_match = (server.env["HTTP_IF_NONE_MATCH"] || "").split(",") .map(&:strip) .map { |s| s.gsub(/^"?W\//, "") } - etag = redis.hget redis_metadata_object_key(user, directory, key), "e" - server.halt 304 if none_match.include? %Q("#{etag}") + existing_metadata = redis.hgetall redis_metadata_object_key(user, directory, key) + if none_match.include? %Q("#{existing_metadata["e"]}") + server.headers["ETag"] = %Q("#{existing_metadata["e"]}") + server.headers["Last-Modified"] = Time.at(existing_metadata["m"].to_i / 1000).httpdate + server.halt 304 + end url = url_for_key(user, directory, key) diff --git a/spec/s3/app_spec.rb b/spec/s3/app_spec.rb index 17188ed..8f818f1 100644 --- a/spec/s3/app_spec.rb +++ b/spec/s3/app_spec.rb @@ -687,6 +687,8 @@ describe "App" do get "/phil/food/aguacate" last_response.status.must_equal 304 + last_response.headers["ETag"].must_equal "\"0815etag\"" + last_response.headers["Last-Modified"].must_equal "Fri, 04 Mar 2016 12:20:18 GMT" end it "responds with 304 when IF_NONE_MATCH header contains weak ETAG matching the current ETag" do @@ -695,6 +697,8 @@ describe "App" do get "/phil/food/aguacate" last_response.status.must_equal 304 + last_response.headers["ETag"].must_equal "\"0815etag\"" + last_response.headers["Last-Modified"].must_equal "Fri, 04 Mar 2016 12:20:18 GMT" end end diff --git a/spec/swift/app_spec.rb b/spec/swift/app_spec.rb index 1cb6aae..c400af4 100644 --- a/spec/swift/app_spec.rb +++ b/spec/swift/app_spec.rb @@ -645,6 +645,8 @@ describe "App" do get "/phil/food/aguacate" last_response.status.must_equal 304 + last_response.headers["ETag"].must_equal "\"0815etag\"" + last_response.headers["Last-Modified"].must_equal "Fri, 04 Mar 2016 12:20:18 GMT" end it "responds with 304 when IF_NONE_MATCH header contains weak ETAG matching the current ETag" do @@ -653,6 +655,8 @@ describe "App" do get "/phil/food/aguacate" last_response.status.must_equal 304 + last_response.headers["ETag"].must_equal "\"0815etag\"" + last_response.headers["Last-Modified"].must_equal "Fri, 04 Mar 2016 12:20:18 GMT" end end