Class: ActionController::CgiRequest

Inherits:
AbstractRequest show all
Defined in:
lib/action_controller/cgi_process.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_SESSION_OPTIONS =
{ :database_manager => CGI::Session::PStore, :prefix => "ruby_sess.", :session_path => "/" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractRequest

#delete?, #domain, #get?, #head?, #host_with_port, #method, #parameters, #path, #path_parameters, #path_parameters=, #port, #port_string, #post?, #protocol, #put?, #raw_post, #relative_url_root, #remote_ip, #request_uri, #ssl?, #subdomains

Constructor Details

#initialize(cgi, session_options = {}) ⇒ CgiRequest

Returns a new instance of CgiRequest.



43
44
45
46
47
# File 'lib/action_controller/cgi_process.rb', line 43

def initialize(cgi, session_options = {})
  @cgi = cgi
  @session_options = session_options
  super()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *arguments) ⇒ Object



99
100
101
# File 'lib/action_controller/cgi_process.rb', line 99

def method_missing(method_id, *arguments)
  @cgi.send(method_id, *arguments) rescue super
end

Instance Attribute Details

#cgiObject

Returns the value of attribute cgi.



38
39
40
# File 'lib/action_controller/cgi_process.rb', line 38

def cgi
  @cgi
end

Instance Method Details

#cookiesObject



69
70
71
# File 'lib/action_controller/cgi_process.rb', line 69

def cookies
  @cgi.cookies.freeze
end

#envObject



65
66
67
# File 'lib/action_controller/cgi_process.rb', line 65

def env
  @cgi.send(:env_table)
end

#hostObject



73
74
75
# File 'lib/action_controller/cgi_process.rb', line 73

def host
  env["HTTP_X_FORWARDED_HOST"] || @cgi.host.to_s.split(":").first
end

#query_parametersObject



56
57
58
59
# File 'lib/action_controller/cgi_process.rb', line 56

def query_parameters
  qs = self.query_string
  qs.empty? ? {} : CGIMethods.parse_query_parameters(query_string)
end

#query_stringObject



49
50
51
52
53
54
# File 'lib/action_controller/cgi_process.rb', line 49

def query_string
  return @cgi.query_string unless @cgi.query_string.nil? || @cgi.query_string.empty?
  parts = env['REQUEST_URI'].split('?')
  parts.shift
  return parts.join('?')
end

#request_parametersObject



61
62
63
# File 'lib/action_controller/cgi_process.rb', line 61

def request_parameters
  CGIMethods.parse_request_parameters(@cgi.params)
end

#reset_sessionObject



94
95
96
97
# File 'lib/action_controller/cgi_process.rb', line 94

def reset_session
  @session.delete
  @session = (@session_options == false ? {} : new_session)
end

#sessionObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/action_controller/cgi_process.rb', line 77

def session
  return @session unless @session.nil?
  begin
    @session = (@session_options == false ? {} : CGI::Session.new(@cgi, session_options_with_string_keys))
    @session["__valid_session"]
    return @session
  rescue ArgumentError => e
    @session.delete if @session
    raise(
      ActionController::SessionRestoreError, 
      "Session contained objects where the class definition wasn't available. " +
      "Remember to require classes for all objects kept in the session. " +
      "The session has been deleted. (Original exception: #{e.message} [#{e.class}])"
    )
  end
end