Class: WebConsole::Middleware
- Inherits:
-
Object
- Object
- WebConsole::Middleware
- Defined in:
- lib/web_console/middleware.rb
Constant Summary collapse
- TEMPLATES_PATH =
File.('../templates', __FILE__)
- DEFAULT_OPTIONS =
{ update_re: %r{/repl_sessions/(?<id>.+?)\z}, binding_change_re: %r{/repl_sessions/(?<id>.+?)/trace\z} }
- UNAVAILABLE_SESSION_MESSAGE =
<<-END.strip_heredoc Session %{id} is is no longer available in memory. If you happen to run on a multi-process server (like Unicorn) the process this request hit doesn't store %{id} in memory. END
- UNACCEPTABLE_REQUEST_MESSAGE =
"A supported version is expected in the Accept header."
- @@whiny_requests =
true
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
24 25 26 27 |
# File 'lib/web_console/middleware.rb', line 24 def initialize(app, = {}) @app = app @options = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#call(env) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/web_console/middleware.rb', line 29 def call(env) request = create_regular_or_whiny_request(env) return @app.call(env) unless request.from_whitelited_ip? if id = id_for_repl_session_update(request) return update_repl_session(id, request) elsif id = id_for_repl_session_stack_frame_change(request) return change_stack_trace(id, request) end status, headers, body = @app.call(env) if exception = env['web_console.exception'] session = Session.from_exception(exception) elsif binding = env['web_console.binding'] session = Session.from_binding(binding) end if session && request.acceptable_content_type? headers["X-Web-Console-Session-Id"] = session.id response = Rack::Response.new(body, status, headers) template = Template.new(env, session) response.write(template.render('index')) response.finish else [ status, headers, body ] end end |