cgi.out(content_type_string='text/html')
cgi.out(headers_hash)
cgi.out(headers_hash)
Instance Public methods
Print an HTTP header and body to $DEFAULT_OUTPUT ($>)
- content_type_string
-
If a string is passed, it is assumed to be the content type.
-
headers_hash
-
This is a Hash of headers, similar to that used by http_header.
-
block
-
A block is required and should evaluate to the body of the response.
Content-Length
is automatically calculated from the size of
the String returned by the content block.
If ENV['REQUEST_METHOD'] == "HEAD"
, then only the
header is output (the content block is still required, but it is ignored).
If the charset is âiso-2022-jpâ or âeuc-jpâ or âshift_jisâ then the content is converted to this charset, and the language is set to âjaâ.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | cgi = CGI . new cgi.out{ "string" } # Content-Type: text/html # Content-Length: 6 # # string cgi.out( "text/plain" ) { "string" } # Content-Type: text/plain # Content-Length: 6 # # string cgi.out( "nph" => true , "status" => "OK" , # == "200 OK" "server" => ENV [ 'SERVER_SOFTWARE' ], "connection" => "close" , "type" => "text/html" , "charset" => "iso-2022-jp" , # Content-Type: text/html; charset=iso-2022-jp "language" => "ja" , "expires" => Time .now + ( 3600 * 24 * 30 ), "cookie" => [cookie1, cookie2], "my_header1" => "my_value" , "my_header2" => "my_value" ) { "string" } # HTTP/1.1 200 OK # Date: Sun, 15 May 2011 17:35:54 GMT # Server: Apache 2.2.0 # Connection: close # Content-Type: text/html; charset=iso-2022-jp # Content-Length: 6 # Content-Language: ja # Expires: Tue, 14 Jun 2011 17:35:54 GMT # Set-Cookie: foo # Set-Cookie: bar # my_header1: my_value # my_header2: my_value # # string |
Please login to continue.