Class: ActionController::RackRequest

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

Overview

:nodoc:

Defined Under Namespace

Classes: SessionFixationAttempt

Constant Summary collapse

DEFAULT_SESSION_OPTIONS =
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS

Constants inherited from AbstractRequest

AbstractRequest::HTTP_METHODS, AbstractRequest::HTTP_METHOD_LOOKUP, AbstractRequest::TRUSTED_PROXIES

Instance Attribute Summary collapse

Attributes inherited from AbstractRequest

#env

Instance Method Summary collapse

Methods inherited from AbstractRequest

#accepts, #body, #cache_format, clean_up_ajax_request_body!, #content_length, #content_type, #delete?, #domain, #etag_matches?, extract_content_type_without_parameters, extract_multipart_boundary, #format, #format=, #fresh?, #get?, #head?, #headers, #host, #host_with_port, #if_modified_since, #if_none_match, #method, #not_modified?, #parameters, parse_multipart_form_parameters, parse_query_parameters, parse_request_parameters, #path, #path_parameters, #path_parameters=, #port, #port_string, #post?, #protocol, #put?, #query_parameters, #raw_host_with_port, #raw_post, #referrer, #relative_url_root, relative_url_root=, #remote_addr, #remote_ip, #request_method, #request_parameters, #request_uri, #session=, #ssl?, #standard_port, #subdomains, #symbolized_path_parameters, #template_format, #url, #xml_http_request?

Constructor Details

#initialize(env, session_options = DEFAULT_SESSION_OPTIONS) ⇒ RackRequest

Returns a new instance of RackRequest.


15
16
17
18
19
20
# File 'lib/action_controller/rack_process.rb', line 15

def initialize(env, session_options = DEFAULT_SESSION_OPTIONS)
  @session_options = session_options
  @env = env
  @cgi = CGIWrapper.new(self)
  super()
end

Instance Attribute Details

#cgiObject (readonly)

Returns the value of attribute cgi


8
9
10
# File 'lib/action_controller/rack_process.rb', line 8

def cgi
  @cgi
end

#session_optionsObject

Returns the value of attribute session_options


7
8
9
# File 'lib/action_controller/rack_process.rb', line 7

def session_options
  @session_options
end

Instance Method Details

#body_streamObject

:nodoc:


44
45
46
# File 'lib/action_controller/rack_process.rb', line 44

def body_stream #:nodoc:
  @env['rack.input']
end

#cookiesObject


52
53
54
55
56
57
58
59
60
61
# File 'lib/action_controller/rack_process.rb', line 52

def cookies
  return {} unless @env["HTTP_COOKIE"]

  unless @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"]
    @env["rack.request.cookie_string"] = @env["HTTP_COOKIE"]
    @env["rack.request.cookie_hash"] = CGI::Cookie::parse(@env["rack.request.cookie_string"])
  end

  @env["rack.request.cookie_hash"]
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/action_controller/rack_process.rb', line 48

def key?(key)
  @env.key?(key)
end

#query_stringObject


35
36
37
38
39
40
41
42
# File 'lib/action_controller/rack_process.rb', line 35

def query_string
  qs = super
  if !qs.blank?
    qs
  else
    @env['QUERY_STRING']
  end
end

#reset_sessionObject


103
104
105
106
# File 'lib/action_controller/rack_process.rb', line 103

def reset_session
  @session.delete if defined?(@session) && @session.is_a?(CGI::Session)
  @session = new_session
end

#server_portObject


63
64
65
# File 'lib/action_controller/rack_process.rb', line 63

def server_port
  @env['SERVER_PORT'].to_i
end

#server_softwareObject


67
68
69
# File 'lib/action_controller/rack_process.rb', line 67

def server_software
  @env['SERVER_SOFTWARE'].split("/").first
end

#sessionObject


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/action_controller/rack_process.rb', line 71

def session
  unless defined?(@session)
    if @session_options == false
      @session = Hash.new
    else
      stale_session_check! do
        if cookie_only? && query_parameters[session_options_with_string_keys['session_key']]
          raise SessionFixationAttempt
        end
        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)
            # CGI::Session raises ArgumentError if 'new_session' == false
            # and no session cookie or query param is present.
            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