class Rack::ETag

Automatically sets the ETag header on all String bodies

Public Instance Methods

call(env) click to toggle source
# 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'] = %Q("#{Digest::MD5.hexdigest(parts.join(""))}")
    [status, headers, parts]
  else
    [status, headers, body]
  end
end

Public Class Methods

new(app) click to toggle source
# File lib/rack/etag.rb, line 6
def initialize(app)
  @app = app
end