Class WEBrick::HTTPResponse
In: lib/nukumi2/xhtmlwebrick.rb
Parent: Object

Methods

set_error  

Public Instance methods

[Source]

    # File lib/nukumi2/xhtmlwebrick.rb, line 6
 6:     def set_error(ex, backtrace=false)
 7:       case ex
 8:       when HTTPStatus::Status 
 9:         @keep_alive = false if HTTPStatus::error?(ex.code)
10:         self.status = ex.code
11:       else 
12:         @keep_alive = false
13:         self.status = HTTPStatus::RC_INTERNAL_SERVER_ERROR
14:       end
15:       @header['content-type'] = "text/html"
16: 
17:       if respond_to?(:create_error_page)
18:         create_error_page()
19:         return
20:       end
21: 
22:       if @request_uri
23:         host, port = @request_uri.host, @request_uri.port
24:       else
25:         host, port = @config[:ServerName], @config[:Port]
26:       end
27: 
28:       @body = ''
29:       @body << "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n<head>\n<title>\#{HTMLUtils::escape(@reason_phrase)}</title>\n<style>\nbody { font-family: \"Trebuchet MS\", Times, serif; }\nhr { height: 1px; color: black; clear: both; }\ndiv.message { white-space: pre; }\n#num { float: left; font-size: 2.5em; margin-right: 0.2em; }\n</style>\n</head>\n<body>\n<h1><span id=\"num\">\#{self.status}</span> \#{HTMLUtils::escape(@reason_phrase)}</h1>\n<div class=\"message\">\#{HTMLUtils::escape(ex.message)}</div>\n<hr />\n"
30: 
31:       if backtrace && $DEBUG
32:         @body << "backtrace of `#{HTMLUtils::escape(ex.class.to_s)}' "
33:         @body << "#{HTMLUtils::escape(ex.message)}"
34:         @body << "<pre>"
35:         ex.backtrace.each{|line| @body << "\t#{line}\n"}
36:         @body << "</pre>\n<hr />"
37:       end
38: 
39:       @body << "<address>\n\#{HTMLUtils::escape(@config[:ServerSoftware])} at\n\#{host}:\#{port}\n</address>\n</body>\n</html>\n"
40:     end

[Validate]