Class: Rack::ETag
- Inherits:
-
Object
- Object
- Rack::ETag
- Defined in:
- lib/rack/contrib/etag.rb
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/rack/contrib/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 |
# File 'lib/rack/contrib/etag.rb', line 10 def call(env) status, headers, body = @app.call(env) if !headers.has_key?('ETag') && body.is_a?(String) headers['ETag'] = %("#{Digest::MD5.hexdigest(body)}") end [status, headers, body] end |