module CGI

Defined in:

Class Method Summary

Class Method Detail

def self.build_form(&block)

Builds a CGI form.

The yielded object has an add method that accepts two arguments, a key (String) and a value (String or Nil). Keys and values are escaped using CGI#escape.

params = CGI.build_form do |form|
  form.add "color", "black"
  form.add "name", "crystal"
  form.add "year", "2012 - today"
end
params #=> "color=black&name=crystal&year=2012%20-%20today"

def self.escape(string : String)

URL-encode a string.

CGI.escape("'Stop!' said Fred") #=> "%27Stop%21%27+said+Fred"

def self.escape(string : String, io : IO)

URL-encode a string and write the result to an IO.


def self.parse(query : String, &block)

Parses an HTTP query and yields each key-value pair

CGI.parse(query) do |key, value|
  # ...
end

def self.parse(query : String)

Parses an HTTP query string into a Hash(String, Array(String))

CGI.parse("foo=bar&foo=baz&qux=zoo") #=> {"foo" => ["bar", "baz"], "qux" => ["zoo"]}

def self.unescape(string : String, io : IO)

URL-decode a string and write the result to an IO.


def self.unescape(string : String)

URL-decode a string.

CGI.unescape("%27Stop%21%27+said+Fred") #=> "'Stop!' said Fred"