class CGI
def out(options = "text/html") # :yield:
# string
#
# my_header2: my_value
# my_header1: my_value
# Set-Cookie: bar
# Set-Cookie: foo
# Expires: Tue, 14 Jun 2011 17:35:54 GMT
# Content-Language: ja
# Content-Length: 6
# Content-Type: text/html; charset=iso-2022-jp
# Connection: close
# Server: Apache 2.2.0
# Date: Sun, 15 May 2011 17:35:54 GMT
# HTTP/1.1 200 OK
"my_header2" => "my_value") { "string" }
"my_header1" => "my_value",
"cookie" => [cookie1, cookie2],
"expires" => Time.now + (3600 * 24 * 30),
"language" => "ja",
# Content-Type: text/html; charset=iso-2022-jp
"charset" => "iso-2022-jp",
"type" => "text/html",
"connection" => "close",
"server" => ENV['SERVER_SOFTWARE'],
"status" => "OK", # == "200 OK"
cgi.out("nph" => true,
# string
#
# Content-Length: 6
# Content-Type: text/plain
cgi.out("text/plain") { "string" }
# string
#
# Content-Length: 6
# Content-Type: text/html
cgi.out{ "string" }
cgi = CGI.new
Example:
content is converted to this charset, and the language is set to "ja".
If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then the
is output (the content block is still required, but it is ignored).
If ENV['REQUEST_METHOD'] == "HEAD", then only the header
the String returned by the content block.
Content-Length is automatically calculated from the size of
A block is required and should evaluate to the body of the response.
+block+::
This is a Hash of headers, similar to that used by #http_header.
+headers_hash+::
If a string is passed, it is assumed to be the content type.
+content_type_string+::
cgi.out(headers_hash)
cgi.out(content_type_string='text/html')
:call-seq:
Print an HTTP header and body to $DEFAULT_OUTPUT ($>)
def out(options = "text/html") # :yield: options = { "type" => options } if options.kind_of?(String) content = yield options["length"] = content.bytesize.to_s output = stdoutput output.binmode if defined? output.binmode output.print http_header(options) output.print content unless "HEAD" == env_table['REQUEST_METHOD'] end