Class: Bullet::Rack
- Inherits:
-
Object
- Object
- Bullet::Rack
- Defined in:
- lib/bullet/rack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #check_html?(headers, response) ⇒ Boolean
-
#empty?(response) ⇒ Boolean
fix issue if response’s body is a Proc.
-
#initialize(app) ⇒ Rack
constructor
A new instance of Rack.
- #no_browser_cache(headers) ⇒ Object
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
3 4 5 |
# File 'lib/bullet/rack.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 23 24 25 |
# File 'lib/bullet/rack.rb', line 7 def call(env) return @app.call(env) unless Bullet.enable? Bullet.start_request status, headers, response = @app.call(env) return [status, headers, response] if empty?(response) if Bullet.notification? if status == 200 and !response.body.frozen? and check_html?(headers, response) response_body = response.body << Bullet.gather_inline_notifications headers['Content-Length'] = response_body.length.to_s end Bullet.perform_out_of_channel_notifications end response_body ||= response.body Bullet.end_request no_browser_cache(headers) if Bullet.disable_browser_cache [status, headers, [response_body]] end |
#check_html?(headers, response) ⇒ Boolean
34 35 36 |
# File 'lib/bullet/rack.rb', line 34 def check_html?(headers, response) headers['Content-Type'] and headers['Content-Type'].include? 'text/html' and response.body =~ %r{<html.*</html>}m end |
#empty?(response) ⇒ Boolean
fix issue if response’s body is a Proc
28 29 30 31 32 |
# File 'lib/bullet/rack.rb', line 28 def empty?(response) # response may be ["Not Found"], ["Move Permanently"], etc. (response.is_a?(Array) && response.size <= 1) || !response.body.is_a?(String) || response.body.empty? end |
#no_browser_cache(headers) ⇒ Object
38 39 40 41 42 |
# File 'lib/bullet/rack.rb', line 38 def no_browser_cache(headers) headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" headers["Pragma"] = "no-cache" headers["Expires"] = "Wed, 09 Sep 2009 09:09:09 GMT" end |