+
#{WEBrick::HTMLUtils.escape(errortext)}
+
+#{WEBrick::HTMLUtils.escape(backtrace) or "\n\n\n"}
+
+
+
#{WEBrick::HTMLUtils.escape(VLINE)}
+
+
+
+HTMLEOF
+ end
+ module_function :error_template
+
+ WEBrick::HTTPResponse.class_exec do
+ attr_accessor :recent_backtrace
+ public
+ def set_backtrace(backtrace)
+ @recent_backtrace = backtrace
+ end
+ def create_error_page
+ @body = Hyde.error_template(@reason_phrase,@recent_backtrace)
+ end
+ end
class Server < WEBrick::HTTPServer
def initialize(config={},&setup)
@@ -15,32 +55,29 @@ module Hyde
@hyde_pathspec = Hyde::Pathspec.new "/", &setup
self.mount_proc '/' do |req,res|
context = Hyde::Context.new(req.path, req, res)
- while context and (not context.exit_loop) do
- context.exit_loop = true
- context = catch :controlled_exit do
- @hyde_pathspec._match(context)
- context
+ begin
+ while context and (not context.exit_loop) do
+ context.exit_loop = true
+ context = catch :controlled_exit do
+ @hyde_pathspec._match(context)
+ context
+ end
+ while postprocessor = context.queue_postprocess.shift do
+ postprocessor.call(context)
+ end
end
+ while finalizer = context.queue_finalize.shift do
+ finalizer.call(context)
+ end
+ rescue Exception => e
+ puts e.message
+ puts e.backtrace
+ res.set_backtrace "#{e.message} (#{e.class})\n#{e.backtrace.join "\n"}"
+ res.status = 500
end
end
end
end
-
- module ErrorPages
- # 404 text
- def error404(request, filepath)
- request.response.status = 404
- if request.handles.include? 404
- request.response.body = request.handles[404].call(
- filepath
- )
- else
- request.response.body = "\n\n