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