Module: Cyberweb::CGI::QueryExtension

Defined in:
lib/cyberweb/cgi/query_extension.rb

Overview

#

Cyberweb::CGI::QueryExtension

Mixin module that provides the following:

  1. 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 variable AUTH_TYPE, and accept will return the value for HTTP_ACCEPT.

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

#

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cookiesObject

#

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
  @cookies
end

#filesObject (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

#paramsObject

#

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.

#

Returns:

  • (Boolean)


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

#

Returns:

  • (Boolean)


337
338
339
# File 'lib/cyberweb/cgi/query_extension.rb', line 337

def multipart?
  @multipart
end
#

Get the raw cookies as a string.

#


102
103
104
# File 'lib/cyberweb/cgi/query_extension.rb', line 102

def raw_cookie
  env_table['HTTP_COOKIE']
end

#raw_cookie2Object

#

raw_cookie2

Get the raw RFC2965 cookies as a string.

#


111
112
113
# File 'lib/cyberweb/cgi/query_extension.rb', line 111

def raw_cookie2
  env_table['HTTP_COOKIE2']
end

#unescape_filename?Boolean

#

unescape_filename?

#

Returns:

  • (Boolean)


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?

#

Returns:

  • (Boolean)


93
94
95
# File 'lib/cyberweb/cgi/query_extension.rb', line 93

def use_commandline_input?
  ::Cyberweb::CGI.use_commandline_input?
end