Sha256: 246cbcd228f849311f5f191c649c12fe6d86bcbed213d9c5d46ba5ca0a6ede63
Contents?: true
Size: 623 Bytes
Versions: 9
Compression:
Stored size: 623 Bytes
Contents
require 'digest/md5' module Rack # Automatically sets the ETag header on all String bodies class ETag def initialize(app) @app = app end 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 private def digest_body(body) digest = Digest::MD5.new parts = [] body.each do |part| digest << part parts << part end [digest.hexdigest, parts] end end end
Version data entries
9 entries across 9 versions & 1 rubygems