def call(env)
app_exception = catch :app_exception do
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 && acceptable_content_type?(headers)
response = Response.new(body, status, headers)
template = Template.new(env, session)
response.headers["X-Web-Console-Session-Id"] = session.id
response.headers["X-Web-Console-Mount-Point"] = mount_point
response.write(template.render('index'))
response.finish
else
[ status, headers, body ]
end
end
rescue => e
WebConsole.logger.error("\n#{e.class}: #{e}\n\tfrom #{e.backtrace.join("\n\tfrom ")}")
raise e
ensure
raise app_exception if Exception === app_exception
end