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.
964 965 966 |
# File 'lib/cgialt/core.rb', line 964 def @cookies end |
#params ⇒ Object
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 |
#accept ⇒ Object
return ENV
890 |
# File 'lib/cgialt/core.rb', line 890 def accept ; return $CGI_ENV['HTTP_ACCEPT'] ; end |
#accept_charset ⇒ Object
return ENV
893 |
# File 'lib/cgialt/core.rb', line 893 def accept_charset ; return $CGI_ENV['HTTP_ACCEPT_CHARSET'] ; end |
#accept_encoding ⇒ Object
return ENV
896 |
# File 'lib/cgialt/core.rb', line 896 def accept_encoding ; return $CGI_ENV['HTTP_ACCEPT_ENCODING'] ; end |
#accept_language ⇒ Object
return ENV
899 |
# File 'lib/cgialt/core.rb', line 899 def accept_language ; return $CGI_ENV['HTTP_ACCEPT_LANGUAGE'] ; end |
#auth_type ⇒ Object
return ENV
845 |
# File 'lib/cgialt/core.rb', line 845 def auth_type ; return $CGI_ENV['AUTH_TYPE'] ; end |
#cache_control ⇒ Object
return ENV
902 |
# File 'lib/cgialt/core.rb', line 902 def cache_control ; return $CGI_ENV['HTTP_CACHE_CONTROL'] ; end |
#content_length ⇒ Object
return Integer(ENV)
839 |
# File 'lib/cgialt/core.rb', line 839 def content_length ; return Integer($CGI_ENV['CONTENT_LENGTH']) ; end |
#content_type ⇒ Object
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 |
#from ⇒ Object
return ENV
905 |
# File 'lib/cgialt/core.rb', line 905 def from ; return $CGI_ENV['HTTP_FROM'] ; end |
#gateway_interface ⇒ Object
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.
1371 1372 1373 |
# File 'lib/cgialt/core.rb', line 1371 def has_key?(*args) @params.has_key?(*args) end |
#host ⇒ Object
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()
-
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
1300 1301 1302 |
# File 'lib/cgialt/core.rb', line 1300 def multipart? @multipart end |
#negotiate ⇒ Object
return ENV
911 |
# File 'lib/cgialt/core.rb', line 911 def negotiate ; return $CGI_ENV['HTTP_NEGOTIATE'] ; end |
#path_info ⇒ Object
return ENV
854 |
# File 'lib/cgialt/core.rb', line 854 def path_info ; return $CGI_ENV['PATH_INFO'] ; end |
#path_translated ⇒ Object
return ENV
857 |
# File 'lib/cgialt/core.rb', line 857 def path_translated ; return $CGI_ENV['PATH_TRANSLATED'] ; end |
#pragma ⇒ Object
return ENV
914 |
# File 'lib/cgialt/core.rb', line 914 def pragma ; return $CGI_ENV['HTTP_PRAGMA'] ; end |
#query_string ⇒ Object
return ENV
860 |
# File 'lib/cgialt/core.rb', line 860 def query_string ; return $CGI_ENV['QUERY_STRING'] ; end |
#raw_cookie ⇒ Object
Get the raw cookies as a string.
944 945 946 |
# File 'lib/cgialt/core.rb', line 944 def return $CGI_ENV['HTTP_COOKIE'] end |
#raw_cookie2 ⇒ Object
Get the raw RFC2965 cookies as a string.
954 955 956 |
# File 'lib/cgialt/core.rb', line 954 def return $CGI_ENV['HTTP_COOKIE2'] end |
#referer ⇒ Object
return ENV
917 |
# File 'lib/cgialt/core.rb', line 917 def referer ; return $CGI_ENV['HTTP_REFERER'] ; end |
#remote_addr ⇒ Object
return ENV
863 |
# File 'lib/cgialt/core.rb', line 863 def remote_addr ; return $CGI_ENV['REMOTE_ADDR'] ; end |
#remote_host ⇒ Object
return ENV
866 |
# File 'lib/cgialt/core.rb', line 866 def remote_host ; return $CGI_ENV['REMOTE_HOST'] ; end |
#remote_ident ⇒ Object
return ENV
869 |
# File 'lib/cgialt/core.rb', line 869 def remote_ident ; return $CGI_ENV['REMOTE_IDENT'] ; end |
#remote_user ⇒ Object
return ENV
872 |
# File 'lib/cgialt/core.rb', line 872 def remote_user ; return $CGI_ENV['REMOTE_USER'] ; end |
#request_method ⇒ Object
return ENV
875 |
# File 'lib/cgialt/core.rb', line 875 def request_method ; return $CGI_ENV['REQUEST_METHOD'] ; end |
#script_name ⇒ Object
return ENV
878 |
# File 'lib/cgialt/core.rb', line 878 def script_name ; return $CGI_ENV['SCRIPT_NAME'] ; end |
#server_name ⇒ Object
return ENV
881 |
# File 'lib/cgialt/core.rb', line 881 def server_name ; return $CGI_ENV['SERVER_NAME'] ; end |
#server_port ⇒ Object
return Integer(ENV)
842 |
# File 'lib/cgialt/core.rb', line 842 def server_port ; return Integer($CGI_ENV['SERVER_PORT']) ; end |
#server_protocol ⇒ Object
return ENV
884 |
# File 'lib/cgialt/core.rb', line 884 def server_protocol ; return $CGI_ENV['SERVER_PROTOCOL'] ; end |
#server_software ⇒ Object
return ENV
887 |
# File 'lib/cgialt/core.rb', line 887 def server_software ; return $CGI_ENV['SERVER_SOFTWARE'] ; end |
#unescape_filename? ⇒ Boolean
:nodoc:
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_agent ⇒ Object
return ENV
920 |
# File 'lib/cgialt/core.rb', line 920 def user_agent ; return $CGI_ENV['HTTP_USER_AGENT'] ; end |