Class ActionController::AbstractRequest
In: vendor/actionpack/lib/action_controller/request.rb
Parent: Object

These methods are available in both the production and test Request objects.

Methods

Public Instance methods

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 133
133:     def cookies
134:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 26
26:     def delete?
27:       method == :delete
28:     end

Returns the domain part of a host, such as rubyonrails.org in "www.rubyonrails.org". You can specify a different tld_length, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk".

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 57
57:     def domain(tld_length = 1)
58:       host.split('.').last(1 + tld_length).join('.')
59:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 127
127:     def env
128:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 14
14:     def get?
15:       method == :get
16:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 30
30:     def head?
31:       method == :head
32:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 130
130:     def host
131:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 105
105:     def host_with_port
106:       env['HTTP_HOST'] || host + port_string
107:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 10
10:     def method
11:       env['REQUEST_METHOD'].downcase.intern
12:     end

Returns both GET and POST parameters in a single hash.

[Source]

   # File vendor/actionpack/lib/action_controller/request.rb, line 5
5:     def parameters
6:       # puts "#{request_parameters.inspect} | #{query_parameters.inspect} | #{path_parameters.inspect}"
7:       @parameters ||= request_parameters.merge(query_parameters).merge(path_parameters).with_indifferent_access
8:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 92
92:     def path
93:       (path_info && !path_info.empty?) ? path_info : (request_uri ? request_uri.split('?').first : '')
94:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 80
80:     def path_info
81:       (/^(.*)\.html$/ =~ env['PATH_INFO']) ? $1 : env['PATH_INFO']
82:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 114
114:     def path_parameters
115:       @path_parameters ||= {}
116:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 109
109:     def path_parameters=(parameters)
110:       @path_parameters = parameters
111:       @parameters = nil
112:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 96
96:     def port
97:       env['SERVER_PORT'].to_i
98:     end

Returns a string like ":8080" if the port is not 80 or 443 while on https.

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 101
101:     def port_string
102:       (protocol == 'http://' && port == 80) || (protocol == 'https://' && port == 443) ? '' : ":#{port}"
103:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 18
18:     def post?
19:       method == :post
20:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 84
84:     def protocol
85:       env["HTTPS"] == "on" ? 'https://' : 'http://'
86:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 22
22:     def put?
23:       method == :put
24:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 121
121:     def query_parameters
122:     end

Receive the raw post data. This is useful for services such as REST, XMLRPC and SOAP which communicate over HTTP POST but don’t use the traditional parameter format.

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 72
72:     def raw_post
73:       env['RAW_POST_DATA']
74:     end

Determine originating IP address. REMOTE_ADDR is the standard but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or HTTP_X_FORWARDED_FOR are set by proxies so check for these before falling back to REMOTE_ADDR. HTTP_X_FORWARDED_FOR may be a comma- delimited list in the case of multiple chained proxies; the first is the originating IP.

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 41
41:     def remote_ip
42:       return env['HTTP_CLIENT_IP'] if env.include? 'HTTP_CLIENT_IP'
43: 
44:       if env.include? 'HTTP_X_FORWARDED_FOR' then
45:         remote_ips = env['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
46:             ip =~ /^unknown$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i
47:         end
48: 
49:         return remote_ips.first.strip unless remote_ips.empty?
50:       end
51: 
52:       return env['REMOTE_ADDR']
53:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 124
124:     def request_parameters
125:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 76
76:     def request_uri
77:       (%r{^\w+\://[^/]+(/.*|$)$} =~ env['REQUEST_URI']) ? $1 : env['REQUEST_URI'] # Remove domain, which webrick puts into the request_uri.
78:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 139
139:     def reset_session
140:     end

[Source]

     # File vendor/actionpack/lib/action_controller/request.rb, line 136
136:     def session
137:     end

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 88
88:     def ssl?
89:       protocol == 'https://'
90:     end

Returns all the subdomains as an array, so ["dev", "www"] would be returned for "dev.www.rubyonrails.org". You can specify a different tld_length, such as 2 to catch ["www"] instead of ["www", "rubyonrails"] in "www.rubyonrails.co.uk".

[Source]

    # File vendor/actionpack/lib/action_controller/request.rb, line 64
64:     def subdomains(tld_length = 1)
65:       parts = host.split('.')
66:       parts - parts.last(1 + tld_length)
67:     end

[Validate]