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

Attributes inherited from AbstractRequest

#env

Instance Method Summary collapse

Methods inherited from AbstractRequest

#accepts, #content_type, #delete?, #domain, #formatted_post?, #get?, #head?, #method, #parameters, #path, #path_parameters, #path_parameters=, #port_string, #post?, #post_format, #protocol, #put?, #raw_post, #relative_url_root, #remote_ip, #request_uri, #server_software, #session=, #ssl?, #standard_port, #subdomains, #symbolized_path_parameters, #xml_http_request?, #xml_post?, #yaml_post?

Constructor Details

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

Returns a new instance of CgiRequest.



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

def initialize(cgi, session_options = {})
  @cgi = cgi
  @session_options = session_options
  @env = @cgi.send(:env_table)
  super()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *arguments) ⇒ Object



126
127
128
# File 'lib/action_controller/cgi_process.rb', line 126

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

Instance Attribute Details

#cgiObject

Returns the value of attribute cgi.



35
36
37
# File 'lib/action_controller/cgi_process.rb', line 35

def cgi
  @cgi
end

#session_optionsObject

Returns the value of attribute session_options.



35
36
37
# File 'lib/action_controller/cgi_process.rb', line 35

def session_options
  @session_options
end

Instance Method Details

#cookiesObject



75
76
77
# File 'lib/action_controller/cgi_process.rb', line 75

def cookies
  @cgi.cookies.freeze
end

#hostObject



91
92
93
# File 'lib/action_controller/cgi_process.rb', line 91

def host
  host_with_port[/^[^:]+/]
end

#host_with_portObject



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

def host_with_port
  if forwarded = env["HTTP_X_FORWARDED_HOST"]
    forwarded.split(/,\s?/).last
  elsif http_host = env['HTTP_HOST']
    http_host
  elsif server_name = env['SERVER_NAME']
    server_name
  else
    "#{env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
  end
end

#portObject



95
96
97
98
99
100
101
# File 'lib/action_controller/cgi_process.rb', line 95

def port
  if host_with_port =~ /:(\d+)$/
    $1.to_i
  else
    standard_port
  end
end

#query_parametersObject



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

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

#query_stringObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/action_controller/cgi_process.rb', line 50

def query_string
  if (qs = @cgi.query_string) && !qs.empty?
    qs
  elsif uri = @env['REQUEST_URI']
    parts = uri.split('?')  
    parts.shift
    parts.join('?')
  else
    @env['QUERY_STRING'] || ''
  end
end

#request_parametersObject



66
67
68
69
70
71
72
73
# File 'lib/action_controller/cgi_process.rb', line 66

def request_parameters
  @request_parameters ||=
    if ActionController::Base.param_parsers.has_key?(content_type)
      CGIMethods.parse_formatted_request_parameters(content_type, @env['RAW_POST_DATA'])
    else
      CGIMethods.parse_request_parameters(@cgi.params)
    end
end

#reset_sessionObject



121
122
123
124
# File 'lib/action_controller/cgi_process.rb', line 121

def reset_session
  @session.delete if CGI::Session === @session
  @session = new_session
end

#sessionObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/action_controller/cgi_process.rb', line 103

def session
  unless @session
    if @session_options == false
      @session = Hash.new
    else
      stale_session_check! do
        if session_options_with_string_keys['new_session'] == true
          @session = new_session
        else
          @session = CGI::Session.new(@cgi, session_options_with_string_keys)
        end
        @session['__valid_session']
      end
    end
  end
  @session
end