# Various extensions and modifications to Webrick. # A nice, XHTML 1.1 valid error page module WEBrick class HTTPResponse def set_error(ex, backtrace=false) case ex when HTTPStatus::Status @keep_alive = false if HTTPStatus::error?(ex.code) self.status = ex.code else @keep_alive = false self.status = HTTPStatus::RC_INTERNAL_SERVER_ERROR end @header['content-type'] = "text/html" if respond_to?(:create_error_page) create_error_page() return end if @request_uri host, port = @request_uri.host, @request_uri.port else host, port = @config[:ServerName], @config[:Port] end @body = '' @body << <<-_end_of_html_ #{HTMLUtils::escape(@reason_phrase)}

#{self.status} #{HTMLUtils::escape(@reason_phrase)}

#{HTMLUtils::escape(ex.message)}

_end_of_html_ if backtrace && $DEBUG @body << "backtrace of `#{HTMLUtils::escape(ex.class.to_s)}' " @body << "#{HTMLUtils::escape(ex.message)}" @body << "
"
        ex.backtrace.each{|line| @body << "\t#{line}\n"}
        @body << "
\n
" end @body << <<-_end_of_html_
#{HTMLUtils::escape(@config[:ServerSoftware])} at #{host}:#{port}
_end_of_html_ end end end