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.
951 952 953 |
# File 'lib/cgialt/core.rb', line 951 def end |
#params ⇒ Object
Get the parameters as a hash of name=>values pairs, where values is an Array.
958 959 960 |
# File 'lib/cgialt/core.rb', line 958 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.
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 |
# File 'lib/cgialt/core.rb', line 1318 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
877 |
# File 'lib/cgialt/core.rb', line 877 def accept ; return ENV['HTTP_ACCEPT'] ; end |
#accept_charset ⇒ Object
return ENV
880 |
# File 'lib/cgialt/core.rb', line 880 def accept_charset ; return ENV['HTTP_ACCEPT_CHARSET'] ; end |
#accept_encoding ⇒ Object
return ENV
883 |
# File 'lib/cgialt/core.rb', line 883 def accept_encoding ; return ENV['HTTP_ACCEPT_ENCODING'] ; end |
#accept_language ⇒ Object
return ENV
886 |
# File 'lib/cgialt/core.rb', line 886 def accept_language ; return ENV['HTTP_ACCEPT_LANGUAGE'] ; end |
#auth_type ⇒ Object
return ENV
832 |
# File 'lib/cgialt/core.rb', line 832 def auth_type ; return ENV['AUTH_TYPE'] ; end |
#cache_control ⇒ Object
return ENV
889 |
# File 'lib/cgialt/core.rb', line 889 def cache_control ; return ENV['HTTP_CACHE_CONTROL'] ; end |
#content_length ⇒ Object
return Integer(ENV)
826 |
# File 'lib/cgialt/core.rb', line 826 def content_length ; return Integer(ENV['CONTENT_LENGTH']) ; end |
#content_type ⇒ Object
return ENV
835 |
# File 'lib/cgialt/core.rb', line 835 def content_type ; return ENV['CONTENT_TYPE'] ; end |
#create_body(is_large) ⇒ Object
:nodoc:
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
# File 'lib/cgialt/core.rb', line 1050 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
892 |
# File 'lib/cgialt/core.rb', line 892 def from ; return ENV['HTTP_FROM'] ; end |
#gateway_interface ⇒ Object
return ENV
838 |
# File 'lib/cgialt/core.rb', line 838 def gateway_interface ; return ENV['GATEWAY_INTERFACE'] ; end |
#has_key?(*args) ⇒ Boolean Also known as: key?, include?
Returns true if a given parameter key exists in the query.
1358 1359 1360 |
# File 'lib/cgialt/core.rb', line 1358 def has_key?(*args) @params.has_key?(*args) end |
#host ⇒ Object
return ENV
895 |
# File 'lib/cgialt/core.rb', line 895 def host ; return ENV['HTTP_HOST'] ; end |
#keys(*args) ⇒ Object
Return all parameter keys as an array.
1353 1354 1355 |
# File 'lib/cgialt/core.rb', line 1353 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
1287 1288 1289 |
# File 'lib/cgialt/core.rb', line 1287 def multipart? @multipart end |
#negotiate ⇒ Object
return ENV
898 |
# File 'lib/cgialt/core.rb', line 898 def negotiate ; return ENV['HTTP_NEGOTIATE'] ; end |
#path_info ⇒ Object
return ENV
841 |
# File 'lib/cgialt/core.rb', line 841 def path_info ; return ENV['PATH_INFO'] ; end |
#path_translated ⇒ Object
return ENV
844 |
# File 'lib/cgialt/core.rb', line 844 def path_translated ; return ENV['PATH_TRANSLATED'] ; end |
#pragma ⇒ Object
return ENV
901 |
# File 'lib/cgialt/core.rb', line 901 def pragma ; return ENV['HTTP_PRAGMA'] ; end |
#query_string ⇒ Object
return ENV
847 |
# File 'lib/cgialt/core.rb', line 847 def query_string ; return ENV['QUERY_STRING'] ; end |
#raw_cookie ⇒ Object
Get the raw cookies as a string.
931 932 933 |
# File 'lib/cgialt/core.rb', line 931 def return ENV['HTTP_COOKIE'] end |
#raw_cookie2 ⇒ Object
Get the raw RFC2965 cookies as a string.
941 942 943 |
# File 'lib/cgialt/core.rb', line 941 def return ENV['HTTP_COOKIE2'] end |
#referer ⇒ Object
return ENV
904 |
# File 'lib/cgialt/core.rb', line 904 def referer ; return ENV['HTTP_REFERER'] ; end |
#remote_addr ⇒ Object
return ENV
850 |
# File 'lib/cgialt/core.rb', line 850 def remote_addr ; return ENV['REMOTE_ADDR'] ; end |
#remote_host ⇒ Object
return ENV
853 |
# File 'lib/cgialt/core.rb', line 853 def remote_host ; return ENV['REMOTE_HOST'] ; end |
#remote_ident ⇒ Object
return ENV
856 |
# File 'lib/cgialt/core.rb', line 856 def remote_ident ; return ENV['REMOTE_IDENT'] ; end |
#remote_user ⇒ Object
return ENV
859 |
# File 'lib/cgialt/core.rb', line 859 def remote_user ; return ENV['REMOTE_USER'] ; end |
#request_method ⇒ Object
return ENV
862 |
# File 'lib/cgialt/core.rb', line 862 def request_method ; return ENV['REQUEST_METHOD'] ; end |
#script_name ⇒ Object
return ENV
865 |
# File 'lib/cgialt/core.rb', line 865 def script_name ; return ENV['SCRIPT_NAME'] ; end |
#server_name ⇒ Object
return ENV
868 |
# File 'lib/cgialt/core.rb', line 868 def server_name ; return ENV['SERVER_NAME'] ; end |
#server_port ⇒ Object
return Integer(ENV)
829 |
# File 'lib/cgialt/core.rb', line 829 def server_port ; return Integer(ENV['SERVER_PORT']) ; end |
#server_protocol ⇒ Object
return ENV
871 |
# File 'lib/cgialt/core.rb', line 871 def server_protocol ; return ENV['SERVER_PROTOCOL'] ; end |
#server_software ⇒ Object
return ENV
874 |
# File 'lib/cgialt/core.rb', line 874 def server_software ; return ENV['SERVER_SOFTWARE'] ; end |
#unescape_filename? ⇒ Boolean
:nodoc:
1066 1067 1068 1069 |
# File 'lib/cgialt/core.rb', line 1066 def unescape_filename? #:nodoc: user_agent = ENV['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
907 |
# File 'lib/cgialt/core.rb', line 907 def user_agent ; return ENV['HTTP_USER_AGENT'] ; end |