Class: Murlsh::EtagAddEncoding

Inherits:
Object
  • Object
show all
Defined in:
lib/murlsh/etag_add_encoding.rb

Overview

Rack middleware to add the content encoding to the end of the ETag because ETag must be different for different representations.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ EtagAddEncoding

Returns a new instance of EtagAddEncoding.



9
# File 'lib/murlsh/etag_add_encoding.rb', line 9

def initialize(app); @app = app; end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/murlsh/etag_add_encoding.rb', line 11

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

  headers = Rack::Utils::HeaderHash.new(headers)

  if headers['ETag']
    headers['ETag'].sub! /(")?$/, "#{headers['Content-Encoding']}\\1"
  end

  [status, headers, body]
end