Class: Rack::ETag
Overview
Automatically sets the ETag header on all String bodies
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ETag
constructor
A new instance of ETag.
Constructor Details
#initialize(app) ⇒ ETag
Returns a new instance of ETag.
6 7 8 |
# File 'lib/vendor/etag.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vendor/etag.rb', line 10 def call(env) status, headers, body = @app.call(env) unless headers.key?('Etag') hashes = [] body.each{|chunk| hashes << chunk.hash } headers['Etag'] = %("#{Digest::MD5.hexdigest(hashes.join)}") end [status, headers, body] end |