Class: ActionController::CgiRequest
Overview
Constant Summary
collapse
- DEFAULT_SESSION_OPTIONS =
{
:database_manager => CGI::Session::PStore,
:prefix => "ruby_sess.",
:session_path => "/"
}
Instance Attribute Summary collapse
#env
Instance Method Summary
collapse
#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
138
139
140
|
# File 'lib/action_controller/cgi_process.rb', line 138
def method_missing(method_id, *arguments)
@cgi.send(method_id, *arguments) rescue super
end
|
Instance Attribute Details
Returns the value of attribute cgi.
35
36
37
|
# File 'lib/action_controller/cgi_process.rb', line 35
def cgi
@cgi
end
|
#session_options ⇒ Object
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
76
77
78
|
# File 'lib/action_controller/cgi_process.rb', line 76
def cookies
@cgi.cookies.freeze
end
|
92
93
94
|
# File 'lib/action_controller/cgi_process.rb', line 92
def host
host_with_port[/^[^:]+/]
end
|
#host_with_port ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/action_controller/cgi_process.rb', line 80
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
|
96
97
98
99
100
101
102
|
# File 'lib/action_controller/cgi_process.rb', line 96
def port
if host_with_port =~ /:(\d+)$/
$1.to_i
else
standard_port
end
end
|
#query_parameters ⇒ Object
62
63
64
65
|
# File 'lib/action_controller/cgi_process.rb', line 62
def query_parameters
@query_parameters ||=
(qs = self.query_string).empty? ? {} : CGIMethods.parse_query_parameters(qs)
end
|
#query_string ⇒ Object
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
|
#reset_session ⇒ Object
133
134
135
136
|
# File 'lib/action_controller/cgi_process.rb', line 133
def reset_session
@session.delete if defined?(@session) && @session.is_a?(CGI::Session)
@session = new_session
end
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/action_controller/cgi_process.rb', line 104
def session
unless defined?(@session)
if @session_options == false
@session = Hash.new
else
stale_session_check! do
case value = session_options_with_string_keys['new_session']
when true
@session = new_session
when false
begin
@session = CGI::Session.new(@cgi, session_options_with_string_keys)
rescue ArgumentError
@session = Hash.new
end
when nil
@session = CGI::Session.new(@cgi, session_options_with_string_keys)
else
raise ArgumentError, "Invalid new_session option: #{value}"
end
@session['__valid_session']
end
end
end
@session
end
|