new(options = {}) public

Create a new CGI instance.


This is the same as using the options_hash form with the value { :tag_maker => tag_maker } Note that it is recommended to use the options_hash form, since it also allows you specify the charset you will accept.


A Hash that recognizes three options:


specifies encoding of received query string. If omitted, @@accept_charset is used. If the encoding is not valid, a CGI::InvalidEncoding will be raised.

Example. Suppose @@accept_charset is “UTF-8”

when not specified:      # @accept_charset # => "UTF-8"

when specified as “EUC-JP”: => "EUC-JP") # => "EUC-JP"


String that specifies which version of the HTML generation methods to use. If not specified, no HTML generation methods will be loaded.

The following values are supported:


HTML 3.x


HTML 4.0


HTML 4.0 Transitional


HTML 4.0 with Framesets




Specifies maximum length of multipart data. Can be an Integer scalar or a lambda, that will be evaluated when the request is parsed. This allows more complex logic to be set when determining whether to accept multipart data (e.g. consult a registered users upload allowance)

Default is 128 * 1024 * 1024 bytes => 268435456) # simple scalar => -> {check_filesystem}) # lambda


If provided, the block is called when an invalid encoding is encountered. For example:

encoding_errors={}>"EUC-JP") do |name,value|
  encoding_errors[name] = value

Finally, if the CGI object is not created in a standard CGI call environment (that is, it can’t locate REQUEST_METHOD in its environment), then it will run in “offline” mode. In this mode, it reads its parameters from the command line or (failing that) from standard input. Otherwise, cookies and other parameters are parsed automatically from the standard CGI locations, which varies according to the REQUEST_METHOD.

Show source
Register or log in to add new notes.