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, #formatted_post?, #get?, #head?, #host_with_port, #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, #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
# 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



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

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



77
78
79
# File 'lib/action_controller/cgi_process.rb', line 77

def cookies
  @cgi.cookies.freeze
end

#envObject



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

def env
  @cgi.send(:env_table)
end

#hostObject



81
82
83
# File 'lib/action_controller/cgi_process.rb', line 81

def host
  env["HTTP_X_FORWARDED_HOST"] || ($1 if env['HTTP_HOST'] && /^(.*):\d+$/ =~ env['HTTP_HOST']) || @cgi.host.to_s.split(":").first || ''
end

#portObject



85
86
87
# File 'lib/action_controller/cgi_process.rb', line 85

def port
  env["HTTP_X_FORWARDED_HOST"] ? standard_port : (port_from_http_host || super)
end

#port_from_http_hostObject



89
90
91
# File 'lib/action_controller/cgi_process.rb', line 89

def port_from_http_host
  $1.to_i if env['HTTP_HOST'] && /:(\d+)$/ =~ env['HTTP_HOST']
end

#query_parametersObject



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

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

#query_stringObject



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

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



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

def request_parameters
  if formatted_post?
    CGIMethods.parse_formatted_request_parameters(post_format, env['RAW_POST_DATA'])
  else
    CGIMethods.parse_request_parameters(@cgi.params)
  end
end

#reset_sessionObject



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

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

#sessionObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/action_controller/cgi_process.rb', line 93

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
    if e.message =~ %r{undefined class/module (\w+)}
      begin
        Module.const_missing($1)
      rescue LoadError, NameError => e
        raise(
          ActionController::SessionRestoreError, 
          "Session contained objects where the class definition wasn't available. " +
          "Remember to require classes for all objects kept in the session. " +
          "(Original exception: #{e.message} [#{e.class}])"
        )
      end
    
      retry
    else
      raise
    end
  end
end