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_errors ⇒ Object
- #serve_javascript ⇒ Object
- #serve_jobs ⇒ Object
- #serve_json ⇒ Object
- #serve_requests ⇒ Object
- #serve_standalone_profiler(env) ⇒ Object
- #serve_stylesheet ⇒ Object
Constructor Details
#initialize(app, config) ⇒ Middleware
Returns a new instance of Middleware.
10 11 12 |
# File 'lib/rorvswild/local/middleware.rb', line 10 def initialize(app, config) @app, @config = app, config end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/rorvswild/local/middleware.rb', line 8 def app @app end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/rorvswild/local/middleware.rb', line 8 def config @config end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rorvswild/local/middleware.rb', line 14 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 when "/rorvswild/requests.json" then serve_requests when "/rorvswild/jobs.json" then serve_jobs when "/rorvswild/errors.json" then serve_errors else (env) end end |
#serve_embed_profiler(env) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rorvswild/local/middleware.rb', line 32 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) && != "hidden" content_length = 0 @current_request = RorVsWild.agent.queue.requests.first 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_errors ⇒ Object
71 72 73 |
# File 'lib/rorvswild/local/middleware.rb', line 71 def serve_errors [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.errors.to_json)] end |
#serve_javascript ⇒ Object
55 56 57 |
# File 'lib/rorvswild/local/middleware.rb', line 55 def serve_javascript [200, {"Content-Type" => "application/javascript"}, StringIO.new(concatenate_javascript)] end |
#serve_jobs ⇒ Object
67 68 69 |
# File 'lib/rorvswild/local/middleware.rb', line 67 def serve_jobs [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.jobs.to_json)] end |
#serve_json ⇒ Object
59 60 61 |
# File 'lib/rorvswild/local/middleware.rb', line 59 def serve_json [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.requests.to_json)] end |
#serve_requests ⇒ Object
63 64 65 |
# File 'lib/rorvswild/local/middleware.rb', line 63 def serve_requests [200, {"Content-Type" => "application/json"}, StringIO.new(RorVsWild.agent.queue.requests.to_json)] end |
#serve_standalone_profiler(env) ⇒ Object
27 28 29 30 |
# File 'lib/rorvswild/local/middleware.rb', line 27 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
51 52 53 |
# File 'lib/rorvswild/local/middleware.rb', line 51 def serve_stylesheet [200, {"Content-Type" => "text/css"}, StringIO.new(concatenate_stylesheet)] end |