method
set_error
v1_9_3_125 -
Show latest stable
- Class:
WEBrick::HTTPResponse
set_error(ex, backtrace=false)public
Creates an error page for exception ex with an optional backtrace
# File lib/webrick/httpresponse.rb, line 275
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; charset=ISO-8859-1"
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 << <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML> <HEAD><TITLE>#{HTMLUtils::escape(@reason_phrase)}</TITLE></HEAD> <BODY> <H1>#{HTMLUtils::escape(@reason_phrase)}</H1> #{HTMLUtils::escape(ex.message)} <HR>
if backtrace && $DEBUG
@body << "backtrace of `#{HTMLUtils::escape(ex.class.to_s)}' "
@body << "#{HTMLUtils::escape(ex.message)}"
@body << "<PRE>"
ex.backtrace.each{|line| @body << "\t#{line}\n"}
@body << "</PRE><HR>"
end
@body << <ADDRESS> #{HTMLUtils::escape(@config[:ServerSoftware])} at #{host}:#{port} </ADDRESS> </BODY></HTML>
end Related methods
- Instance methods
- []
- []=
- chunked=
- chunked?
- content_length
- content_length=
- content_type
- content_type=
- each
- keep_alive?
- send_body
- send_header
- send_response
- set_error
- set_redirect
- setup_header
- status=
- status_line
- to_s
- Class methods
- new
- Private methods
-
_send_file -
_write_data -
send_body_io -
send_body_string