Class: Macmillan::Utils::Middleware::WeakEtags

Inherits:
Object
  • Object
show all
Defined in:
lib/macmillan/utils/middleware/weak_etags.rb

Overview

Rack Middleware for use when proxying a rack app with Nginx using gzip compression.

Nginx will convert ETags generated by our rack apps from STRONG etags, to WEAK etags, this middleware converts the ETags back to STRONG for use within the consuming app.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ WeakEtags

Returns a new instance of WeakEtags.



12
13
14
# File 'lib/macmillan/utils/middleware/weak_etags.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
# File 'lib/macmillan/utils/middleware/weak_etags.rb', line 16

def call(env)
  dup.process(env)
end

#process(env) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/macmillan/utils/middleware/weak_etags.rb', line 20

def process(env)
  etag = env['HTTP_IF_NONE_MATCH']

  if etag && etag.match(/^W\//)
    env['HTTP_IF_NONE_MATCH'] = etag.gsub(/^W\//, '')
  end

  @app.call(env)
end