Module: CGI::QueryExtension (Ruby 2.3.7)
Description: Module : CGI::QueryExtension - Ruby 2.3.7

- Home
- Core 2.3.7
- Std-lib 2.3.7
- Downloads

Support for the Ruby 2.3 series has ended. See here for reference.

### Home Classes Methods

### In Files

- cgi/core.rb

### Methods

- #[]
- #has_key?
- #include?
- #key?
- #keys
- #multipart?
- #params=
- #raw_cookie
- #raw_cookie2

### Class/Module Index

Quicksearch

- CGI
- CGI::Cookie
- CGI::HTML3
- CGI::HTML4
- CGI::HTML4Fr
- CGI::HTML4Tr
- CGI::HTML5
- CGI::HtmlExtension
- CGI::InvalidEncoding
- CGI::QueryExtension
- CGI::Session
- CGI::Session::FileStore
- CGI::Session::MemoryStore
- CGI::Session::NullStore
- CGI::Session::PStore
- CGI::Util

No matching classes.

# CGI::QueryExtension

Mixin module that provides the following:

1. Access to the CGI environment variables as methods. See documentation to the CGI class for a list of these variables. The methods are exposed by removing the leading `HTTP_` (if it exists) and downcasing the name. For example, `auth_type` will return the environment variable `AUTH_TYPE`, and `accept` will return the value for `HTTP_ACCEPT`.

2. Access to cookies, including the cookies attribute.

3. Access to parameters, including the params attribute, and overloading [] to perform parameter value lookup by key.

4. The initialize_query method, for initializing the above mechanisms, handling multipart forms, and allowing the class to be used in “offline” mode.

### Attributes

cookies[RW]

Get the cookies as a hash of cookie-name=>Cookie pairs.

files[R]

Get the uploaded files as a hash of name=>values pairs

params[R]

Get the parameters as a hash of name=>values pairs, where values is an Array.

### Public Instance Methods

[](key) click to toggle source

Get the value for the parameter with a given key.

If the parameter has multiple values, only the first will be retrieved; use params to get the array of values.

                   # File cgi/core.rb, line 694
    def [](key)
      params = @params[key]
      return '' unless params
      value = params[0]
      if @multipart
        if value
          return value
        elsif defined? StringIO
          StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
        else
          Tempfile.new("CGI",encoding: Encoding::ASCII_8BIT)
        end
      else
        str = if value then value.dup else "" end
        str
      end
    end

has_key?(*args) click to toggle source

Returns true if a given query string parameter exists.

                   # File cgi/core.rb, line 718
    def has_key?(*args)
      @params.has_key?(*args)
    end

Also aliased as: key?, include?
include?(*args) click to toggle source
Alias for: has_key?
key?(*args) click to toggle source
Alias for: has_key?
keys(*args) click to toggle source

Return all query parameter names as an array of String.

                   # File cgi/core.rb, line 713
    def keys(*args)
      @params.keys(*args)
    end

multipart?() click to toggle source

Returns whether the form contained multipart/form-data

                   # File cgi/core.rb, line 686
    def multipart?
      @multipart
    end

params=(hash) click to toggle source

Set all the parameters.

                   # File cgi/core.rb, line 455
    def params=(hash)
      @params.clear
      @params.update(hash)
    end

raw_cookie() click to toggle source

Get the raw cookies as a string.

                   # File cgi/core.rb, line 435
    def raw_cookie
      env_table["HTTP_COOKIE"]
    end

raw_cookie2() click to toggle source

Get the raw RFC2965 cookies as a string.

                   # File cgi/core.rb, line 440
    def raw_cookie2
      env_table["HTTP_COOKIE2"]
    end