Class: RorVsWild::Local::Middleware
- Inherits:
-
Object
- Object
- RorVsWild::Local::Middleware
- Includes:
- ERB::Util
- Defined in:
- lib/rorvswild/local/middleware.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config) ⇒ Middleware
constructor
A new instance of Middleware.
- #serve_embed_profiler(env) ⇒ Object
- #serve_javascript ⇒ Object
- #serve_json ⇒ Object
- #serve_standalone_profiler(env) ⇒ Object
- #serve_stylesheet ⇒ Object
Constructor Details
#initialize(app, config) ⇒ Middleware
Returns a new instance of Middleware.
8 9 10 |
# File 'lib/rorvswild/local/middleware.rb', line 8 def initialize(app, config) @app, @config = app, config end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/rorvswild/local/middleware.rb', line 6 def app @app end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/rorvswild/local/middleware.rb', line 6 def config @config end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/rorvswild/local/middleware.rb', line 12 def call(env) case env["PATH_INFO"] when "/rorvswild" then serve_standalone_profiler(env) when "/rorvswild.css" then serve_stylesheet when "/rorvswild.js" then serve_javascript when "/rorvswild.json" then serve_json else (env) end end |
#serve_embed_profiler(env) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rorvswild/local/middleware.rb', line 27 def (env) status, headers, body = app.call(env) status = status.to_i if status >= 200 && status < 300 && headers["Content-Type"] && headers["Content-Type"].include?("text/html") if headers["Content-Encoding"] log_incompatible_middleware_warning elsif body.respond_to?(:each) content_length = 0 body.each do |string| inject_into(string) content_length += string.size end headers["Content-Length"] = content_length.to_s if headers["Content-Length"] end end [status, headers, body] end |
#serve_javascript ⇒ Object
49 50 51 |
# File 'lib/rorvswild/local/middleware.rb', line 49 def serve_javascript [200, {"Content-Type" => "application/javascript"}, StringIO.new(concatenate_javascript)] end |
#serve_json ⇒ Object
53 54 55 |
# File 'lib/rorvswild/local/middleware.rb', line 53 def serve_json [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.requests.to_json)] end |
#serve_standalone_profiler(env) ⇒ Object
22 23 24 25 |
# File 'lib/rorvswild/local/middleware.rb', line 22 def serve_standalone_profiler(env) html = inject_into(empty_html_page) [200, {"Content-Type" => "text/html; charset=utf-8"}, StringIO.new(html || empty_html_page)] end |
#serve_stylesheet ⇒ Object
45 46 47 |
# File 'lib/rorvswild/local/middleware.rb', line 45 def serve_stylesheet [200, {"Content-Type" => "text/css"}, StringIO.new(concatenate_stylesheet)] end |