These methods are available in both the production and test Request objects.
- cookies
- delete?
- domain
- env
- get?
- head?
- host
- host_with_port
- method
- parameters
- path
- path_parameters
- path_parameters=
- port
- port_string
- post?
- protocol
- put?
- query_parameters
- raw_post
- relative_url_root
- remote_ip
- request_parameters
- request_uri
- reset_session
- session
- ssl?
- subdomains
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 140
140: def cookies
141: end
[ show source ]
# File vendor/rails/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".
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 57
57: def domain(tld_length = 1)
58: host.split('.').last(1 + tld_length).join('.')
59: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 134
134: def env
135: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 14
14: def get?
15: method == :get
16: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 30
30: def head?
31: method == :head
32: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 137
137: def host
138: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 112
112: def host_with_port
113: env['HTTP_HOST'] || host + port_string
114: end
[ show source ]
# File vendor/rails/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.
[ show source ]
# File vendor/rails/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
returns the interpreted path to requested resource after all the installation directory of this application was taken into account
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 90
90: def path
91: path = request_uri ? request_uri.split('?').first : ''
92:
93: # cut off the part of the url which leads to the installation directory of this app
94: path[relative_url_root.length..-1]
95: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 121
121: def path_parameters
122: @path_parameters ||= {}
123: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 116
116: def path_parameters=(parameters)
117: @path_parameters = parameters
118: @parameters = nil
119: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 103
103: def port
104: env['SERVER_PORT'].to_i
105: end
Returns a string like ":8080" if the port is not 80 or 443 while on https.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 108
108: def port_string
109: (protocol == 'http://' && port == 80) || (protocol == 'https://' && port == 443) ? '' : ":#{port}"
110: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 18
18: def post?
19: method == :post
20: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 80
80: def protocol
81: env["HTTPS"] == "on" ? 'https://' : 'http://'
82: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 22
22: def put?
23: method == :put
24: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 128
128: def query_parameters
129: 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.
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 72
72: def raw_post
73: env['RAW_POST_DATA']
74: end
returns the path minus the web server relative installation directory
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 99
99: def relative_url_root
100: File.dirname(env["SCRIPT_NAME"].to_s).gsub /(^\.$|^\/$)/, ''
101: 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.
[ show source ]
# File vendor/rails/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
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 131
131: def request_parameters
132: end
[ show source ]
# File vendor/rails/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
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 146
146: def reset_session
147: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 143
143: def session
144: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 84
84: def ssl?
85: protocol == 'https://'
86: 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".
[ show source ]
# File vendor/rails/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