Class: Murlsh::FarFutureExpires
- Inherits:
-
Object
- Object
- Murlsh::FarFutureExpires
- Defined in:
- lib/murlsh/far_future_expires.rb
Overview
Rack middleware to set a far future expires header for urls that match patterns.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ FarFutureExpires
constructor
A new instance of FarFutureExpires.
Constructor Details
#initialize(app, options = {}) ⇒ FarFutureExpires
Returns a new instance of FarFutureExpires.
10 11 12 13 14 |
# File 'lib/murlsh/far_future_expires.rb', line 10 def initialize(app, ={}) @app = app @patterns = [:patterns] ? [*[:patterns]] : [] @future = [:future] || 'Wed, 22 Jun 2019 20:07:00 GMT' end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/murlsh/far_future_expires.rb', line 16 def call(env) status, headers, body = @app.call(env) req = Rack::Request.new(env) headers = Rack::Utils::HeaderHash.new(headers) @patterns.each do |pattern| if pattern.match(req.path) headers['Expires'] = @future break end end [status, headers, body] end |