lib/merb/merb_handler.rb in merb-0.0.8 vs lib/merb/merb_handler.rb in merb-0.0.9
- old
+ new
@@ -65,22 +65,21 @@
# gives us the best trade off for multi threaded performance
# of thread safe, and a lock around calls to your controller actions.
@guard.synchronize {
controller.dispatch(action)
}
- rescue Exception => e
+ rescue Object => e
response.start(500) do |head,out|
head["Content-Type"] = "text/html"
- MERB_LOGGER.info(exception(e))
- out << html_exception(e)
+ MERB_LOGGER.info(Merb.exception(e))
+ out << Merb.html_exception(e)
end
return
end
sendfile, clength = nil
response.status = controller.status
-
# check for the X-SENDFILE header from your Merb::Controller
# and serve the file directly instead of buffering.
controller.headers.each do |k, v|
if k =~ /^X-SENDFILE$/i
sendfile = v
@@ -115,13 +114,14 @@
controller.body.close
end
else
MERB_LOGGER.info("Response status: #{response.status}\nComplete Request took: #{Time.now - start} seconds\n\n")
# render response from successful controller
- response.send_status((controller.body||='').length)
+ body = (controller.body.to_s rescue '')
+ response.send_status(body.length)
response.send_header
- response.write(controller.body)
+ response.write(body)
end
end
end
# This is where we grab the incoming request PATH_INFO
@@ -129,40 +129,29 @@
# which controller and method to run.
# returns a 2 element tuple of:
# [controller, action]
def handle(request)
path = request.params[Mongrel::Const::PATH_INFO].sub(/\/+/, '/')
- path = path[0..-2] if (path[-1] == ?/)
+ path = path[0..-2] if (path[-1] == ?/) && path.size > 1
route = Merb::RouteMatcher.new.route_request(path)
[ instantiate_controller(route[:controller], request.body, request.params, route),
route[:action] ]
end
# take a controller class name string and reload or require
# the right controller file then CamelCase it and turn it
# into a new object passing in the request and response.
# this is where your Merb::Controller is instantiated.
def instantiate_controller(controller_name, req, env, params)
- if !File.exist?(Merb::Server.config[:dist_root]+"/app/controllers/#{controller_name.snake_case}.rb")
+ if !File.exist?(DIST_ROOT+"/app/controllers/#{controller_name.snake_case}.rb")
raise Merb::MissingControllerFile
end
begin
controller_name.import
return Object.const_get( controller_name.camel_case ).new(req, env, params)
rescue RuntimeError
warn "Error getting instance of '#{controller_name.camel_case}': #{$!}"
raise $!
end
- end
-
- # format exception message for browser display
- def html_exception(e)
- "<html><body><h2>Merb Error!</h2><p>#{ e.message } - (#{ e.class })\n" <<
- "#{(e.backtrace or []).join('<br />')}</p></body></html>"
- end
-
- def exception(e)
- "#{ e.message } - (#{ e.class })\n" <<
- "#{(e.backtrace or []).join("\n")}"
end
end
\ No newline at end of file