Module: CGI::QueryExtension

Included in:
CGI
Defined in:
lib/cgialt/core.rb

Overview

Mixin module. It provides the follow functionality groups:

  1. Access to CGI environment variables as methods. See documentation to the CGI class for a list of these variables.

  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 initialising the above mechanisms, handling multipart forms, and allowing the class to be used in “offline” mode.

Defined Under Namespace

Modules: Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cookiesObject

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



964
965
966
# File 'lib/cgialt/core.rb', line 964

def cookies
  @cookies
end

#paramsObject

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



971
972
973
# File 'lib/cgialt/core.rb', line 971

def params
  @params
end

Instance Method Details

#[](key) ⇒ Object

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.



1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
# File 'lib/cgialt/core.rb', line 1331

def [](key)
  params = @params[key]
  value = params[0]
  if @multipart
    return value if value
    return defined?(StringIO) ? StringIO.new('') : Tempfile.new('CGI')
  else
    str = value ? value.dup : ''
    str.extend(Value)
    str.set_params(params)
    return str
  end
end

#acceptObject

return ENV



890
# File 'lib/cgialt/core.rb', line 890

def accept            ; return $CGI_ENV['HTTP_ACCEPT']          ; end

#accept_charsetObject

return ENV



893
# File 'lib/cgialt/core.rb', line 893

def accept_charset    ; return $CGI_ENV['HTTP_ACCEPT_CHARSET']  ; end

#accept_encodingObject

return ENV



896
# File 'lib/cgialt/core.rb', line 896

def accept_encoding   ; return $CGI_ENV['HTTP_ACCEPT_ENCODING'] ; end

#accept_languageObject

return ENV



899
# File 'lib/cgialt/core.rb', line 899

def accept_language   ; return $CGI_ENV['HTTP_ACCEPT_LANGUAGE'] ; end

#auth_typeObject

return ENV



845
# File 'lib/cgialt/core.rb', line 845

def auth_type         ; return $CGI_ENV['AUTH_TYPE']            ; end

#cache_controlObject

return ENV



902
# File 'lib/cgialt/core.rb', line 902

def cache_control     ; return $CGI_ENV['HTTP_CACHE_CONTROL']   ; end

#content_lengthObject

return Integer(ENV)



839
# File 'lib/cgialt/core.rb', line 839

def content_length    ; return Integer($CGI_ENV['CONTENT_LENGTH']) ; end

#content_typeObject

return ENV



848
# File 'lib/cgialt/core.rb', line 848

def content_type      ; return $CGI_ENV['CONTENT_TYPE']         ; end

#create_body(is_large) ⇒ Object

:nodoc:



1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
# File 'lib/cgialt/core.rb', line 1063

def create_body(is_large)  #:nodoc:
  if is_large
    require 'tempfile'
    body = Tempfile.new('CGI')
  else
    begin
      require 'stringio'
      body = StringIO.new
    rescue LoadError
      require 'tempfile'
      body = Tempfile.new('CGI')
    end
  end
  body.binmode if defined? body.binmode
  return body
end

#fromObject

return ENV



905
# File 'lib/cgialt/core.rb', line 905

def from              ; return $CGI_ENV['HTTP_FROM']            ; end

#gateway_interfaceObject

return ENV



851
# File 'lib/cgialt/core.rb', line 851

def gateway_interface ; return $CGI_ENV['GATEWAY_INTERFACE']    ; end

#has_key?(*args) ⇒ Boolean Also known as: key?, include?

Returns true if a given parameter key exists in the query.

Returns:

  • (Boolean)


1371
1372
1373
# File 'lib/cgialt/core.rb', line 1371

def has_key?(*args)
  @params.has_key?(*args)
end

#hostObject

return ENV



908
# File 'lib/cgialt/core.rb', line 908

def host              ; return $CGI_ENV['HTTP_HOST']            ; end

#keys(*args) ⇒ Object

Return all parameter keys as an array.



1366
1367
1368
# File 'lib/cgialt/core.rb', line 1366

def keys(*args)
  @params.keys(*args)
end

#multipart?Boolean

*** original *def initialize_query()

*

*end *private :initialize_query *** /original

Returns:

  • (Boolean)


1300
1301
1302
# File 'lib/cgialt/core.rb', line 1300

def multipart?
  @multipart
end

#negotiateObject

return ENV



911
# File 'lib/cgialt/core.rb', line 911

def negotiate         ; return $CGI_ENV['HTTP_NEGOTIATE']       ; end

#path_infoObject

return ENV



854
# File 'lib/cgialt/core.rb', line 854

def path_info         ; return $CGI_ENV['PATH_INFO']            ; end

#path_translatedObject

return ENV



857
# File 'lib/cgialt/core.rb', line 857

def path_translated   ; return $CGI_ENV['PATH_TRANSLATED']      ; end

#pragmaObject

return ENV



914
# File 'lib/cgialt/core.rb', line 914

def pragma            ; return $CGI_ENV['HTTP_PRAGMA']          ; end

#query_stringObject

return ENV



860
# File 'lib/cgialt/core.rb', line 860

def query_string      ; return $CGI_ENV['QUERY_STRING']         ; end

Get the raw cookies as a string.



944
945
946
# File 'lib/cgialt/core.rb', line 944

def raw_cookie
  return $CGI_ENV['HTTP_COOKIE']
end

#raw_cookie2Object

Get the raw RFC2965 cookies as a string.



954
955
956
# File 'lib/cgialt/core.rb', line 954

def raw_cookie2
  return $CGI_ENV['HTTP_COOKIE2']
end

#refererObject

return ENV



917
# File 'lib/cgialt/core.rb', line 917

def referer           ; return $CGI_ENV['HTTP_REFERER']         ; end

#remote_addrObject

return ENV



863
# File 'lib/cgialt/core.rb', line 863

def remote_addr       ; return $CGI_ENV['REMOTE_ADDR']          ; end

#remote_hostObject

return ENV



866
# File 'lib/cgialt/core.rb', line 866

def remote_host       ; return $CGI_ENV['REMOTE_HOST']          ; end

#remote_identObject

return ENV



869
# File 'lib/cgialt/core.rb', line 869

def remote_ident      ; return $CGI_ENV['REMOTE_IDENT']         ; end

#remote_userObject

return ENV



872
# File 'lib/cgialt/core.rb', line 872

def remote_user       ; return $CGI_ENV['REMOTE_USER']          ; end

#request_methodObject

return ENV



875
# File 'lib/cgialt/core.rb', line 875

def request_method    ; return $CGI_ENV['REQUEST_METHOD']       ; end

#script_nameObject

return ENV



878
# File 'lib/cgialt/core.rb', line 878

def script_name       ; return $CGI_ENV['SCRIPT_NAME']          ; end

#server_nameObject

return ENV



881
# File 'lib/cgialt/core.rb', line 881

def server_name       ; return $CGI_ENV['SERVER_NAME']          ; end

#server_portObject

return Integer(ENV)



842
# File 'lib/cgialt/core.rb', line 842

def server_port       ; return Integer($CGI_ENV['SERVER_PORT'])    ; end

#server_protocolObject

return ENV



884
# File 'lib/cgialt/core.rb', line 884

def server_protocol   ; return $CGI_ENV['SERVER_PROTOCOL']      ; end

#server_softwareObject

return ENV



887
# File 'lib/cgialt/core.rb', line 887

def server_software   ; return $CGI_ENV['SERVER_SOFTWARE']      ; end

#unescape_filename?Boolean

:nodoc:

Returns:

  • (Boolean)


1079
1080
1081
1082
# File 'lib/cgialt/core.rb', line 1079

def unescape_filename?  #:nodoc:
  user_agent = $CGI_ENV['HTTP_USER_AGENT']
  return /Mac/ni.match(user_agent) && /Mozilla/ni.match(user_agent) && !/MSIE/ni.match(user_agent)
end

#user_agentObject

return ENV



920
# File 'lib/cgialt/core.rb', line 920

def user_agent        ; return $CGI_ENV['HTTP_USER_AGENT']      ; end