Module: CGI::QueryExtension
- Included in:
- CGI
- Defined in:
- lib/cgialt/core.rb
Overview
Mixin module. It provides the follow functionality groups:
-
Access to CGI environment variables as methods. See documentation to the CGI class for a list of these variables.
-
Access to cookies, including the cookies attribute.
-
Access to parameters, including the params attribute, and overloading
-
to perform parameter value lookup by key.
-
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
-
#cookies ⇒ Object
Get the cookies as a hash of cookie-name=>Cookie pairs.
-
#params ⇒ Object
Get the parameters as a hash of name=>values pairs, where values is an Array.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get the value for the parameter with a given key.
-
#accept ⇒ Object
return ENV.
-
#accept_charset ⇒ Object
return ENV.
-
#accept_encoding ⇒ Object
return ENV.
-
#accept_language ⇒ Object
return ENV.
-
#auth_type ⇒ Object
return ENV.
-
#cache_control ⇒ Object
return ENV.
-
#content_length ⇒ Object
return Integer(ENV).
-
#content_type ⇒ Object
return ENV.
-
#create_body(is_large) ⇒ Object
:nodoc:.
-
#from ⇒ Object
return ENV.
-
#gateway_interface ⇒ Object
return ENV.
-
#has_key?(*args) ⇒ Boolean
(also: #key?, #include?)
Returns true if a given parameter key exists in the query.
-
#host ⇒ Object
return ENV.
-
#keys(*args) ⇒ Object
Return all parameter keys as an array.
-
#multipart? ⇒ Boolean
*** original *def initialize_query() * if (“POST” == env_table) and * %r|Amultipart/form-data.*boundary="?(+)"?|n.match(env_table) * boundary = $1.dup * @multipart = true * @params = read_multipart(boundary, Integer(env_table)) * else * @multipart = false * @params = CGI::parse( * case env_table * when “GET”, “HEAD” * if defined?(MOD_RUBY) * Apache::request.args or “” * else * env_table or “” * end * when “POST” * stdinput.binmode if defined? stdinput.binmode * stdinput.read(Integer(env_table)) or ” * else * read_from_cmdline * end * ) * end * * @cookies = CGI::Cookie::parse((env_table or env_table)) *end *private :initialize_query *** /original.
-
#negotiate ⇒ Object
return ENV.
-
#path_info ⇒ Object
return ENV.
-
#path_translated ⇒ Object
return ENV.
-
#pragma ⇒ Object
return ENV.
-
#query_string ⇒ Object
return ENV.
-
#raw_cookie ⇒ Object
Get the raw cookies as a string.
-
#raw_cookie2 ⇒ Object
Get the raw RFC2965 cookies as a string.
-
#referer ⇒ Object
return ENV.
-
#remote_addr ⇒ Object
return ENV.
-
#remote_host ⇒ Object
return ENV.
-
#remote_ident ⇒ Object
return ENV.
-
#remote_user ⇒ Object
return ENV.
-
#request_method ⇒ Object
return ENV.
-
#script_name ⇒ Object
return ENV.
-
#server_name ⇒ Object
return ENV.
-
#server_port ⇒ Object
return Integer(ENV).
-
#server_protocol ⇒ Object
return ENV.
-
#server_software ⇒ Object
return ENV.
-
#unescape_filename? ⇒ Boolean
:nodoc:.
-
#user_agent ⇒ Object
return ENV.
Instance Attribute Details
#cookies ⇒ Object
Get the cookies as a hash of cookie-name=>Cookie pairs.
977 978 979 |
# File 'lib/cgialt/core.rb', line 977 def @cookies end |
#params ⇒ Object
Get the parameters as a hash of name=>values pairs, where values is an Array.
984 985 986 |
# File 'lib/cgialt/core.rb', line 984 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.
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 |
# File 'lib/cgialt/core.rb', line 1352 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 |
#accept ⇒ Object
return ENV
903 |
# File 'lib/cgialt/core.rb', line 903 def accept ; return env_table['HTTP_ACCEPT'] ; end |
#accept_charset ⇒ Object
return ENV
906 |
# File 'lib/cgialt/core.rb', line 906 def accept_charset ; return env_table['HTTP_ACCEPT_CHARSET'] ; end |
#accept_encoding ⇒ Object
return ENV
909 |
# File 'lib/cgialt/core.rb', line 909 def accept_encoding ; return env_table['HTTP_ACCEPT_ENCODING'] ; end |
#accept_language ⇒ Object
return ENV
912 |
# File 'lib/cgialt/core.rb', line 912 def accept_language ; return env_table['HTTP_ACCEPT_LANGUAGE'] ; end |
#auth_type ⇒ Object
return ENV
858 |
# File 'lib/cgialt/core.rb', line 858 def auth_type ; return env_table['AUTH_TYPE'] ; end |
#cache_control ⇒ Object
return ENV
915 |
# File 'lib/cgialt/core.rb', line 915 def cache_control ; return env_table['HTTP_CACHE_CONTROL'] ; end |
#content_length ⇒ Object
return Integer(ENV)
852 |
# File 'lib/cgialt/core.rb', line 852 def content_length ; return Integer(env_table['CONTENT_LENGTH']) ; end |
#content_type ⇒ Object
return ENV
861 |
# File 'lib/cgialt/core.rb', line 861 def content_type ; return env_table['CONTENT_TYPE'] ; end |
#create_body(is_large) ⇒ Object
:nodoc:
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 |
# File 'lib/cgialt/core.rb', line 1083 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 |
#from ⇒ Object
return ENV
918 |
# File 'lib/cgialt/core.rb', line 918 def from ; return env_table['HTTP_FROM'] ; end |
#gateway_interface ⇒ Object
return ENV
864 |
# File 'lib/cgialt/core.rb', line 864 def gateway_interface ; return env_table['GATEWAY_INTERFACE'] ; end |
#has_key?(*args) ⇒ Boolean Also known as: key?, include?
Returns true if a given parameter key exists in the query.
1392 1393 1394 |
# File 'lib/cgialt/core.rb', line 1392 def has_key?(*args) @params.has_key?(*args) end |
#host ⇒ Object
return ENV
921 |
# File 'lib/cgialt/core.rb', line 921 def host ; return env_table['HTTP_HOST'] ; end |
#keys(*args) ⇒ Object
Return all parameter keys as an array.
1387 1388 1389 |
# File 'lib/cgialt/core.rb', line 1387 def keys(*args) @params.keys(*args) end |
#multipart? ⇒ Boolean
*** original *def initialize_query()
-
if (“POST” == env_table) and
-
%r|Amultipart/form-data.*boundary="?(+)"?|n.match(env_table)
-
boundary = $1.dup
-
@multipart = true
-
@params = read_multipart(boundary, Integer(env_table))
-
else
-
@multipart = false
-
@params = CGI::parse(
-
case env_table
-
when “GET”, “HEAD”
-
if defined?(MOD_RUBY)
-
Apache::request.args or “”
-
else
-
env_table or “”
-
end
-
when “POST”
-
stdinput.binmode if defined? stdinput.binmode
-
else
-
read_from_cmdline
-
end
-
)
-
end
*
-
@cookies = CGI::Cookie::parse((env_table or env_table))
*end *private :initialize_query *** /original
1321 1322 1323 |
# File 'lib/cgialt/core.rb', line 1321 def multipart? @multipart end |
#negotiate ⇒ Object
return ENV
924 |
# File 'lib/cgialt/core.rb', line 924 def negotiate ; return env_table['HTTP_NEGOTIATE'] ; end |
#path_info ⇒ Object
return ENV
867 |
# File 'lib/cgialt/core.rb', line 867 def path_info ; return env_table['PATH_INFO'] ; end |
#path_translated ⇒ Object
return ENV
870 |
# File 'lib/cgialt/core.rb', line 870 def path_translated ; return env_table['PATH_TRANSLATED'] ; end |
#pragma ⇒ Object
return ENV
927 |
# File 'lib/cgialt/core.rb', line 927 def pragma ; return env_table['HTTP_PRAGMA'] ; end |
#query_string ⇒ Object
return ENV
873 |
# File 'lib/cgialt/core.rb', line 873 def query_string ; return env_table['QUERY_STRING'] ; end |
#raw_cookie ⇒ Object
Get the raw cookies as a string.
957 958 959 |
# File 'lib/cgialt/core.rb', line 957 def return env_table['HTTP_COOKIE'] end |
#raw_cookie2 ⇒ Object
Get the raw RFC2965 cookies as a string.
967 968 969 |
# File 'lib/cgialt/core.rb', line 967 def return env_table['HTTP_COOKIE2'] end |
#referer ⇒ Object
return ENV
930 |
# File 'lib/cgialt/core.rb', line 930 def referer ; return env_table['HTTP_REFERER'] ; end |
#remote_addr ⇒ Object
return ENV
876 |
# File 'lib/cgialt/core.rb', line 876 def remote_addr ; return env_table['REMOTE_ADDR'] ; end |
#remote_host ⇒ Object
return ENV
879 |
# File 'lib/cgialt/core.rb', line 879 def remote_host ; return env_table['REMOTE_HOST'] ; end |
#remote_ident ⇒ Object
return ENV
882 |
# File 'lib/cgialt/core.rb', line 882 def remote_ident ; return env_table['REMOTE_IDENT'] ; end |
#remote_user ⇒ Object
return ENV
885 |
# File 'lib/cgialt/core.rb', line 885 def remote_user ; return env_table['REMOTE_USER'] ; end |
#request_method ⇒ Object
return ENV
888 |
# File 'lib/cgialt/core.rb', line 888 def request_method ; return env_table['REQUEST_METHOD'] ; end |
#script_name ⇒ Object
return ENV
891 |
# File 'lib/cgialt/core.rb', line 891 def script_name ; return env_table['SCRIPT_NAME'] ; end |
#server_name ⇒ Object
return ENV
894 |
# File 'lib/cgialt/core.rb', line 894 def server_name ; return env_table['SERVER_NAME'] ; end |
#server_port ⇒ Object
return Integer(ENV)
855 |
# File 'lib/cgialt/core.rb', line 855 def server_port ; return Integer(env_table['SERVER_PORT']) ; end |
#server_protocol ⇒ Object
return ENV
897 |
# File 'lib/cgialt/core.rb', line 897 def server_protocol ; return env_table['SERVER_PROTOCOL'] ; end |
#server_software ⇒ Object
return ENV
900 |
# File 'lib/cgialt/core.rb', line 900 def server_software ; return env_table['SERVER_SOFTWARE'] ; end |
#unescape_filename? ⇒ Boolean
:nodoc:
1099 1100 1101 1102 |
# File 'lib/cgialt/core.rb', line 1099 def unescape_filename? #:nodoc: user_agent = env_table['HTTP_USER_AGENT'] return /Mac/ni.match(user_agent) && /Mozilla/ni.match(user_agent) && !/MSIE/ni.match(user_agent) end |
#user_agent ⇒ Object
return ENV
933 |
# File 'lib/cgialt/core.rb', line 933 def user_agent ; return env_table['HTTP_USER_AGENT'] ; end |