Skip to content

Commit

Permalink
only construct one request in an engine
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Sep 30, 2015
1 parent ff30db1 commit 8f8b7ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
16 changes: 7 additions & 9 deletions railties/lib/rails/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,6 @@ def run_load_hooks! # :nodoc:
self
end

# Implements call according to the Rack API. It simply
# dispatches the request to the underlying middleware stack.
def call(env)
req = ActionDispatch::Request.new env
env["ORIGINAL_FULLPATH"] = req.fullpath
env["ORIGINAL_SCRIPT_NAME"] = req.script_name
super(env)
end

# Reload application routes regardless if they changed or not.
def reload_routes!
routes_reloader.reload!
Expand Down Expand Up @@ -517,6 +508,13 @@ def validate_secret_key_config! #:nodoc:

private

def build_request(env)
req = super
env["ORIGINAL_FULLPATH"] = req.fullpath
env["ORIGINAL_SCRIPT_NAME"] = req.script_name
req
end

def build_middleware
config.app_middleware + super
end
Expand Down
15 changes: 10 additions & 5 deletions railties/lib/rails/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,8 @@ def endpoint

# Define the Rack API for this engine.
def call(env)
env.merge!(env_config)
req = ActionDispatch::Request.new env
req.routes = routes
req.engine_script_name = req.script_name
app.call(env)
req = build_request env
app.call req.env
end

# Defines additional Rack env configuration that is added on each call.
Expand Down Expand Up @@ -697,6 +694,14 @@ def _all_load_paths #:nodoc:

private

def build_request(env)
env.merge!(env_config)
req = ActionDispatch::Request.new env
req.routes = routes
req.engine_script_name = req.script_name
req
end

def build_middleware
config.middleware
end
Expand Down

0 comments on commit 8f8b7ae

Please sign in to comment.