Class: Rack::ETag

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/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/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
# File 'lib/rack/etag.rb', line 10

def call(env)
  status, headers, body = @app.call(env)

  if !headers.has_key?('ETag')
    digest, body = digest_body(body)
    headers['ETag'] = %("#{digest}")
  end

  [status, headers, body]
end