Class CGI
In: cgi_rdoc.rb
Parent: Object
Methods
escape    escapeElement    escapeHTML    header    out    rfc1123_date    unescape    unescapeElement    unescapeHTML   
Public Class methods
escape(string)

url_encoded_string = CGI::escape("string")

unescape(string)

string = CGI::unescape("url encoded string")

escapeHTML(string)

CGI::escapeHTML("string")

Escapes the characters & \ " < >

unescapeHTML(string)

CGI::unescapeHTML("HTML escaped string")

escapeElement(string, *elements)

Escape one or more elements in a string.

Examples:

 print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
    "<BR>&lt;A HREF="url"&gt;&lt;/A&gt"

 print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
    "<BR>&lt;A HREF="url"&gt;&lt;/A&gt"
unescapeElement(string, *elements)

Unescape one or more elements.a

  print CGI::unescapeElement(
          CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
     "&lt;BR&gt;<A HREF="url"></A>"

  print CGI::unescapeElement(
         CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
     "&lt;BR&gt;<A HREF="url"></A>"
rfc1123_date(time)

Convert a time to an RFC1123 format date string

  CGI::rfc1123_date(Time.now)
      Sat, 01 Jan 2000 00:00:00 GMT
Public Instance methods
header(options = "text/html")

Make an HTTP header string

 header
    Content-Type: text/html

 header("text/plain")
    Content-Type: text/plain
 header({"nph"        => true,
         "status"     => "OK",  # == "200 OK"
         "server"     => ENV['SERVER_SOFTWARE'],
         "connection" => "close",
         "type"       => "text/html",
         "charset"    => "iso-2022-jp",
         "language"   => "ja",
         "expires"    => Time.now + 30,
         "cookie"     => [cookie1, cookie2],
         "my_header1" => "my_value"
         "my_header2" => "my_value"})

Header will not convert charset.

Status is one of

 "OK"                  --> "200 OK"
 "PARTIAL_CONTENT"     --> "206 Partial Content"
 "MULTIPLE_CHOICES"    --> "300 Multiple Choices"
 "MOVED"               --> "301 Moved Permanently"
 "REDIRECT"            --> "302 Found"
 "NOT_MODIFIED"        --> "304 Not Modified"
 "BAD_REQUEST"         --> "400 Bad Request"
 "AUTH_REQUIRED"       --> "401 Authorization Required"
 "FORBIDDEN"           --> "403 Forbidden"
 "NOT_FOUND"           --> "404 Not Found"
 "METHOD_NOT_ALLOWED"  --> "405 Method Not Allowed"
 "NOT_ACCEPTABLE"      --> "406 Not Acceptable"
 "LENGTH_REQUIRED"     --> "411 Length Required"
 "PRECONDITION_FAILED" --> "412 Rrecondition Failed"
 "SERVER_ERROR"        --> "500 Internal Server Error"
 "NOT_IMPLEMENTED"     --> "501 Method Not Implemented"
 "BAD_GATEWAY"         --> "502 Bad Gateway"
 "VARIANT_ALSO_VARIES" --> "506 Variant Also Negotiates"
out(options = "text/html") {|| ...}

Print HTTP header and a given string to $DEFAULT_OUTPUT ($>)

 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" }

If "HEAD" == REQUEST_METHOD then output only HTTP header.

If charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then convert string charset, and set language to "ja".