Skip to content

Commit

Permalink
Backport 3.0 features for Rails 5 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
gsamokovarov committed Jan 27, 2016
1 parent 487df5a commit e2190ea
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

## master (unreleased)

## 2.3.0

* [#181](https://github.com/rails/web-console/pull/181) Log internal Web Console errors ([@schneems])
* [#150](https://github.com/rails/web-console/pull/150) Revert #150. ([@gsamokovarov])

## 2.2.1

* [#150](https://github.com/rails/web-console/pull/150) Change config.development_only default until 4.2.4 is released.
* [#150](https://github.com/rails/web-console/pull/150) Change config.development_only default until 4.2.4 is released. ([@gsamokovarov])

## 2.2.0

Expand Down Expand Up @@ -48,3 +53,4 @@
[@parterburn]: https://github.com/parterburn
[@sh19910711]: https://github.com/sh19910711
[@frenesim]: https://github.com/frenesim
[@schneems]: https://github.com/schneems
7 changes: 5 additions & 2 deletions lib/web_console/extensions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
ActionDispatch::DebugExceptions.class_eval do
def render_exception_with_web_console(env, exception)
render_exception_without_web_console(env, exception).tap do
def render_exception_with_web_console(request, exception)
render_exception_without_web_console(request, exception).tap do
# Retain superficial Rails 5 compatibility.
env = Hash === request ? request : request.env

error = ActionDispatch::ExceptionWrapper.new(env, exception).exception

# Get the original exception if ExceptionWrapper decides to follow it.
Expand Down
59 changes: 36 additions & 23 deletions lib/web_console/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,41 @@ def initialize(app)
end

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
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)
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 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)
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 ]
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

private
Expand Down Expand Up @@ -120,5 +127,11 @@ def respond_with_unacceptable_request
{ output: I18n.t('errors.unacceptable_request') }
end
end

def call_app(env)
@app.call(env)
rescue => e
throw :app_exception, e
end
end
end
4 changes: 0 additions & 4 deletions lib/web_console/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ class Railtie < ::Rails::Railtie
config.web_console = ActiveSupport::OrderedOptions.new
config.web_console.whitelisted_ips = %w( 127.0.0.1 ::1 )

# See rails/web-console#150 and rails/rails#20319. Revert when Ruby on
# Rails 4.2.4 is released.
config.web_console.development_only = false

initializer 'web_console.initialize' do
require 'web_console/extensions'

Expand Down
2 changes: 1 addition & 1 deletion lib/web_console/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module WebConsole
VERSION = '2.2.1'
VERSION = '2.3.0'
end

0 comments on commit e2190ea

Please sign in to comment.