Class: Rack::ETag

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/contrib/etag.rb

Overview

Automatically sets the ETag header on all String bodies

Instance Method Summary collapse

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