class CGI
def http_header(options='text/html')
"my_header2" => "my_value")
"my_header1" => "my_value",
"cookie" => [cookie1, cookie2],
"expires" => Time.now + 30,
"language" => "ja",
"length" => 103,
# Content-Type: text/html; charset=iso-2022-jp
"charset" => "iso-2022-jp",
"type" => "text/html",
"connection" => "close",
"server" => ENV['SERVER_SOFTWARE'],
# "status" => "200 GOOD",
"status" => "OK", # == "200 OK"
http_header("nph" => true,
# Content-Type: text/plain
http_header("text/plain")
# Content-Type: text/html
http_header
Examples:
Other headers can also be set; they are appended as key: value.
@output_cookies field.
These cookies are in addition to the cookies held in the
whose values are literal cookie strings or Cookie objects.
an Array of literal cookie strings or Cookie objects; or a hash all of
value can be the literal string of the cookie; a CGI::Cookie object;
A cookie or cookies, returned as one or more Set-Cookie headers. The
cookie::
object, returned as the Expires header.
expires:: The time on which the current content expires, as a +Time+
header.
language:: The language of the content, returned as the Content-Language
Content-Length header.
length:: The length of the content that will be sent, returned as the
instance, "close".
connection:: The connection type, returned as the Connection header (for
server:: The server software, returned as the Server header.
VARIANT_ALSO_VARIES:: 506 Variant Also Negotiates
BAD_GATEWAY:: 502 Bad Gateway
NOT_IMPLEMENTED:: 501 Method Not Implemented
SERVER_ERROR:: 500 Internal Server Error
PRECONDITION_FAILED:: 412 Precondition Failed
LENGTH_REQUIRED:: 411 Length Required
NOT_ACCEPTABLE:: 406 Not Acceptable
METHOD_NOT_ALLOWED:: 405 Method Not Allowed
NOT_FOUND:: 404 Not Found
FORBIDDEN:: 403 Forbidden
AUTH_REQUIRED:: 401 Authorization Required
BAD_REQUEST:: 400 Bad Request
NOT_MODIFIED:: 304 Not Modified
REDIRECT:: 302 Found
MOVED:: 301 Moved Permanently
MULTIPLE_CHOICES:: 300 Multiple Choices
PARTIAL_CONTENT:: 206 Partial Content
OK:: 200 OK
values are:
The HTTP status code as a String, returned as the Status header. The
status::
"connection" if not explicitly set.
code, and date; and sets default values for "server" and
nph:: A boolean value. If true, prepend protocol string and status
charset:: The charset of the body, appended to the Content-Type header.
type:: The Content-Type header. Defaults to "text/html"
A Hash of header values. The following header keys are recognized:
+headers_hash+::
If this form is used, this string is the Content-Type
+content_type_string+::
Includes the empty line that ends the header block.
http_header(headers_hash)
http_header(content_type_string="text/html")
:call-seq:
Create an HTTP header block as a string.
def http_header(options='text/html') if options.is_a?(String) content_type = options buf = _header_for_string(content_type) elsif options.is_a?(Hash) if options.size == 1 && options.has_key?('type') content_type = options['type'] buf = _header_for_string(content_type) else buf = _header_for_hash(options.dup) end else raise ArgumentError.new("expected String or Hash but got #{options.class}") end if defined?(MOD_RUBY) _header_for_modruby(buf) return '' else buf << EOL # empty line of separator return buf end end # http_header()