Add If-None-Match support to Server::ETag

This commit is contained in:
0x1eef 2023-07-05 15:28:00 -03:00
parent b048016dc9
commit d5704b0813

View file

@ -1,15 +1,19 @@
# frozen_string_literal: true
class Server::ETag < Rack::ETag
ETAGS = {}
def initialize(app)
@app = app
end
def call(env)
status, headers, body = super(env)
if env["HTTP_IF_NONE_MATCH"] == headers["etag"]
headers = ETAGS[env["REQUEST_PATH"]] || {}
if headers["etag"] && headers["etag"] == env["HTTP_IF_NONE_MATCH"]
[304, headers, [""]]
else
status, headers, body = super(env)
ETAGS[env["REQUEST_PATH"]] = headers
[status, headers, body]
end
end