diff options
Diffstat (limited to 'actionpack/lib/action_controller/request.rb')
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index d3d65ec0ec..94ec7d27af 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -29,7 +29,8 @@ module ActionController def head? method == :head 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 @@ -53,40 +54,47 @@ module ActionController # Returns the domain part of a host, such as rubyonrails.org in "www.rubyonrails.org". You can specify # a different <tt>tld_length</tt>, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk". def domain(tld_length = 1) - host.split(".").last(1 + tld_length).join(".") + host.split('.').last(1 + tld_length).join('.') end # Returns all the subdomains as an array, so ["dev", "www"] would be returned for "dev.www.rubyonrails.org". # You can specify a different <tt>tld_length</tt>, such as 2 to catch ["www"] instead of ["www", "rubyonrails"] # in "www.rubyonrails.co.uk". def subdomains(tld_length = 1) - parts = host.split(".") + parts = host.split('.') parts - parts.last(1 + tld_length) end + # Recieve 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. + def raw_post + env['RAW_POST_DATA'] + end + def request_uri - env["REQUEST_URI"] + env['REQUEST_URI'] end def protocol - port == 443 ? "https://" : "http://" + port == 443 ? 'https://' : 'http://' end def ssl? - protocol == "https://" + protocol == 'https://' end def path - request_uri ? request_uri.split("?").first : "" + request_uri ? request_uri.split('?').first : '' end def port - env["SERVER_PORT"].to_i + env['SERVER_PORT'].to_i end # Returns a string like ":8080" if the port is not 80 or 443 while on https. def port_string - (protocol == "http://" && port == 80) || (protocol == "https://" && port == 443) ? "" : ":#{port}" + (protocol == 'http://' && port == 80) || (protocol == 'https://' && port == 443) ? '' : ":#{port}" end def host_with_port |