Module: Cyberweb::CGI::QueryExtension
- Defined in:
- lib/cyberweb/cgi/query_extension.rb
Overview
#
Cyberweb::CGI::QueryExtension
Mixin module that provides the following:
-
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 variableAUTH_TYPE
, andaccept
will return the value forHTTP_ACCEPT
. -
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 initializing the above mechanisms, handling multipart forms, and allowing the class to be used in “offline” mode.
#
Instance Attribute Summary collapse
-
#cookies ⇒ Object
# === cookies.
-
#files ⇒ Object
readonly
# === files.
-
#params ⇒ Object
# === params.
Instance Method Summary collapse
-
#[](key) ⇒ Object
# === [].
-
#create_body(is_large) ⇒ Object
# === create_body ======================================================================= #.
-
#has_key?(*i) ⇒ Boolean
(also: #key?, #include?)
# === has_key?.
-
#keys(*i) ⇒ Object
# === keys.
-
#multipart? ⇒ Boolean
# === multipart?.
-
#raw_cookie ⇒ Object
# === raw_cookie.
-
#raw_cookie2 ⇒ Object
# === raw_cookie2.
-
#unescape_filename? ⇒ Boolean
# === unescape_filename? ======================================================================= #.
-
#use_commandline_input? ⇒ Boolean
# === use_commandline_input? ======================================================================= #.
Instance Attribute Details
#cookies ⇒ Object
#
cookies
Get the cookies as a hash of cookie-name=>Cookie pairs.
#
55 56 57 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 55 def @cookies end |
#files ⇒ Object (readonly)
#
files
Get the uploaded files as a hash of name=>values pairs
#
70 71 72 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 70 def files @files end |
#params ⇒ Object
#
params
Get the parameters as a hash of name=>values pairs, where values is an Array.
#
63 64 65 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 63 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.
#
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 411 def [](key) params = @params[key] return '' unless params value = params.first 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 |
#create_body(is_large) ⇒ Object
#
create_body
#
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 257 def create_body(is_large) if is_large require 'tempfile' body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT) else begin require 'stringio' body = StringIO.new(''.force_encoding(Encoding::ASCII_8BIT)) rescue LoadError require 'tempfile' body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT) end end body.binmode if defined? body.binmode return body end |
#has_key?(*i) ⇒ Boolean Also known as: key?, include?
#
has_key?
Returns true if a given query string parameter exists.
#
296 297 298 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 296 def has_key?(*i) @params.has_key?(*i) end |
#keys(*i) ⇒ Object
#
keys
Return all query parameter names as an array of String.
#
287 288 289 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 287 def keys(*i) @params.keys(*i) end |
#multipart? ⇒ Boolean
#
multipart?
Returns whether the form contained multipart/form-data
#
337 338 339 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 337 def multipart? @multipart end |
#raw_cookie ⇒ Object
#
raw_cookie
Get the raw cookies as a string.
#
102 103 104 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 102 def env_table['HTTP_COOKIE'] end |
#raw_cookie2 ⇒ Object
#
raw_cookie2
Get the raw RFC2965 cookies as a string.
#
111 112 113 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 111 def env_table['HTTP_COOKIE2'] end |
#unescape_filename? ⇒ Boolean
#
unescape_filename?
#
277 278 279 280 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 277 def unescape_filename? user_agent = $CGI_ENV['HTTP_USER_AGENT'] return /Mac/i.match(user_agent) && /Mozilla/i.match(user_agent) && !/MSIE/i.match(user_agent) end |
#use_commandline_input? ⇒ Boolean
#
use_commandline_input?
#
93 94 95 |
# File 'lib/cyberweb/cgi/query_extension.rb', line 93 def use_commandline_input? ::Cyberweb::CGI.use_commandline_input? end |