An HTTP response. This is filled in by the service or do_* methods of a WEBrick HTTP Servlet.
- #
- C
- E
- K
- N
- S
[RW] | body | Body may be a String or IO subclass. |
[R] | config | Configuration for this response |
[R] | cookies | Response cookies |
[RW] | filename | Filename of the static file in this response. Only used by the FileHandler servlet. |
[R] | header | Response header |
[R] | http_version | HTTP Response version |
[RW] | keep_alive | Is this a keep-alive response? |
[RW] | reason_phrase | Response reason phrase (“OK”) |
[RW] | request_http_version | Request HTTP version for this response |
[RW] | request_method | Request method for this response |
[RW] | request_uri | Request URI for this response |
[R] | sent_size | Bytes sent in this response |
[R] | status | Response status code (200) |
Creates a new HTTP response object. WEBrick::Config::HTTP is the default configuration.
# File lib/webrick/httpresponse.rb, line 94 def initialize(config) @config = config @buffer_size = config[:OutputBufferSize] @logger = config[:Logger] @header = Hash.new @status = HTTPStatus::RC_OK @reason_phrase = nil @http_version = HTTPVersion::convert(@config[:HTTPVersion]) @body = '' @keep_alive = true @cookies = [] @request_method = nil @request_uri = nil @request_http_version = @http_version # temporary @chunked = false @filename = nil @sent_size = 0 end
Retrieves the response header field
Sets the response header field
to value
Enables chunked transfer encoding.
Will this response body be returned using chunked transfer-encoding?
The content-length header
Sets the content-length header to len
The content-type header
Sets the content-type header to type
Iterates over each header in the resopnse
Will this response's connection be kept alive?
Creates an error page for exception ex
with an optional
backtrace
# File lib/webrick/httpresponse.rb, line 330 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 << <<-_end_of_html_ <!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> _end_of_html_ 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 << <<-_end_of_html_ <ADDRESS> #{HTMLUtils::escape(@config[:ServerSoftware])} at #{host}:#{port} </ADDRESS> </BODY> </HTML> _end_of_html_ end
Redirects to url
with a WEBrick::HTTPStatus::Redirect
status
.
Example:
res.set_redirect WEBrick::HTTPStatus::TemporaryRedirect
Sets the response's status to the status
code