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
- xhr?
- xml_http_request?
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 156
156: def cookies
157: 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 150
150: def env
151: 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 153
153: def host
154: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 120
120: def host_with_port
121: env['HTTP_HOST'] || host + port_string
122: 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 98
98: def path
99: path = request_uri ? request_uri.split('?').first : ''
100:
101: # cut off the part of the url which leads to the installation directory of this app
102: path[relative_url_root.length..-1]
103: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 129
129: def path_parameters
130: @path_parameters ||= {}
131: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 124
124: def path_parameters=(parameters)
125: @path_parameters = parameters
126: @parameters = nil
127: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 111
111: def port
112: env['SERVER_PORT'].to_i
113: 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 116
116: def port_string
117: (protocol == 'http://' && port == 80) || (protocol == 'https://' && port == 443) ? '' : ":#{port}"
118: 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 88
88: def protocol
89: env["HTTPS"] == "on" ? 'https://' : 'http://'
90: 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 144
144: def query_parameters
145: 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 107
107: def relative_url_root
108: File.dirname(env["SCRIPT_NAME"].to_s).gsub /(^\.$|^\/$)/, ''
109: 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 147
147: def request_parameters
148: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 76
76: def request_uri
77: unless env['REQUEST_URI'].nil?
78: (%r{^\w+\://[^/]+(/.*|$)$} =~ env['REQUEST_URI']) ? $1 : env['REQUEST_URI'] # Remove domain, which webrick puts into the request_uri.
79: else # REQUEST_URI is blank under IIS - get this from PATH_INFO and SCRIPT_NAME
80: script_filename = env["SCRIPT_NAME"].to_s.match(%r{[^/]+$})
81: request_uri = env["PATH_INFO"]
82: request_uri.sub!(/#{script_filename}\//, '') unless script_filename.nil?
83: request_uri += '?' + env["QUERY_STRING"] unless env["QUERY_STRING"].nil? || env["QUERY_STRING"].empty?
84: return request_uri
85: end
86: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 162
162: def reset_session
163: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 159
159: def session
160: end
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 92
92: def ssl?
93: protocol == 'https://'
94: 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
Alias for xml_http_request?
Returns true if the request’s "X-Requested-With" header contains "XMLHttpRequest". (The Prototype Javascript library sends this header with every Ajax request.)
[ show source ]
# File vendor/rails/actionpack/lib/action_controller/request.rb, line 136
136: def xml_http_request?
137: env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
138: end