Class: Timestamper::RackMiddleware
- Inherits:
-
Object
- Object
- Timestamper::RackMiddleware
- Defined in:
- lib/timestamper/rack_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RackMiddleware
constructor
A new instance of RackMiddleware.
Constructor Details
#initialize(app) ⇒ RackMiddleware
Returns a new instance of RackMiddleware.
3 4 5 |
# File 'lib/timestamper/rack_middleware.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/timestamper/rack_middleware.rb', line 7 def call(env) Timestamper.instance.reset status, headers, response = @app.call(env) if headers["Content-Type"].to_s =~ /^text\/html/ if status == 200 and headers['Last-Modified'].nil? = Timestamper.instance.updated_at || Time.now headers['Last-Modified'] = .httpdate end # rails return response object with body method, sinatra just returns array of 1 string response = response.respond_to?(:body) ? response.body : response [status, headers, response] else [status, headers, response] end end |