lib/doozer/app.rb in doozer-0.3.1 vs lib/doozer/app.rb in doozer-0.4.0
- old
+ new
@@ -26,10 +26,12 @@
# match env.path_info against the route compile
#p env.inspect
route = Doozer::Routing::Routes::match(path)
# p "path: #{path}"
# p "route: #{route.inspect}"
+ app = nil
+
if not route.nil?
if route.app.nil?
extra_params = route.extra_params(path)
controller_klass = handler(route.controller.to_sym)
controller = controller_klass.new({:env=>env, :route=>route, :extra_params=>extra_params, :port=>@options[:Port]})
@@ -61,14 +63,17 @@
r = Rack::Response.new(controller.render_result, route.status, {"Content-Type" => route.content_type})
#execution_time(nil,:end)
r.set_cookie('flash',{:value=>nil, :path=>'/'})
r.set_cookie('session',{:value=>controller.session_to_cookie(), :path=>'/'})
+ r = controller.write_response_cookies(r)
+
+
# finalize the request
controller.finished!
controller = nil
- return r.to_a
+ app = r.to_a
rescue Doozer::Redirect => redirect
# set the status to the one defined in the route which type of redirect do we need to handle?
status = (route.status==301) ? 301 : 302
# check to make sure the status wasn't manually changed in the controller
@@ -80,11 +85,11 @@
r.set_cookie('session',{:value=>controller.session_to_cookie(), :path=>'/'})
# finalize the request
controller.finished!
controller = nil
- return r.to_a
+ app = r.to_a
rescue => e
# finalize the request
controller.finished!
controller = nil
@@ -93,20 +98,25 @@
for line in e.backtrace
logger.error(" #{line}")
end
logger.error("Printing env variables:")
logger.error(env.inspect)
- return [500, {"Content-Type" => "text/html"}, @@errors[500]]
+ app = [500, {"Content-Type" => "text/html"}, @@errors[500]]
else
raise e
end
end
else
- return route.app.call(env)
+ app = route.app.call(env)
end
else
- return [404, {"Content-Type" => "text/html"}, @@errors[404]]
+ app = [404, {"Content-Type" => "text/html"}, @@errors[404]]
end
+
+ # pass the app through route.middleware_after if defined
+ app = route.middleware_after.new(app, {:config=>Doozer::Configs, :route=>route}).call(env) if route.middleware_after
+
+ return app
end
def execution_time(name = nil, point = :start)
if Doozer::Configs.rack_env == :development
@execution_time_name = name if name
\ No newline at end of file