diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-09-03 17:58:47 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-09-03 17:58:47 +0100 |
commit | 6ef35461dc7148ce37ed602d65a24f6c883fd044 (patch) | |
tree | c190505eaa8b98b4fcae4403bdd4776957d07785 /actionpack/lib/action_controller/request.rb | |
parent | 10fe6a6d8940300dd6698ec38e9c9573404e687d (diff) | |
download | rails-6ef35461dc7148ce37ed602d65a24f6c883fd044.tar.gz rails-6ef35461dc7148ce37ed602d65a24f6c883fd044.tar.bz2 rails-6ef35461dc7148ce37ed602d65a24f6c883fd044.zip |
Merge docrails
Diffstat (limited to 'actionpack/lib/action_controller/request.rb')
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index d793ade702..8e6cfb41dc 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -22,7 +22,7 @@ module ActionController # such as { 'RAILS_ENV' => 'production' }. attr_reader :env - # The true HTTP request method as a lowercase symbol, such as <tt>:get</tt>. + # The true HTTP request \method as a lowercase symbol, such as <tt>:get</tt>. # UnknownHttpMethod is raised for invalid methods not listed in ACCEPTED_HTTP_METHODS. def request_method method = @env['REQUEST_METHOD'] @@ -32,7 +32,7 @@ module ActionController end memoize :request_method - # The HTTP request method as a lowercase symbol, such as <tt>:get</tt>. + # The HTTP request \method as a lowercase symbol, such as <tt>:get</tt>. # Note, HEAD is returned as <tt>:get</tt> since the two are functionally # equivalent from the application's perspective. def method @@ -59,19 +59,21 @@ module ActionController request_method == :delete end - # Is this a HEAD request? <tt>request.method</tt> sees HEAD as <tt>:get</tt>, - # so check the HTTP method directly. + # Is this a HEAD request? Since <tt>request.method</tt> sees HEAD as <tt>:get</tt>, + # this \method checks the actual HTTP \method directly. def head? request_method == :head end # Provides access to the request's HTTP headers, for example: - # request.headers["Content-Type"] # => "text/plain" + # + # request.headers["Content-Type"] # => "text/plain" def headers ActionController::Http::Headers.new(@env) end memoize :headers + # Returns the content length of the request as an integer. def content_length @env['CONTENT_LENGTH'].to_i end @@ -79,14 +81,14 @@ module ActionController # The MIME type of the HTTP request, such as Mime::XML. # - # For backward compatibility, the post format is extracted from the + # For backward compatibility, the post \format is extracted from the # X-Post-Data-Format HTTP header if present. def content_type Mime::Type.lookup(content_type_without_parameters) end memoize :content_type - # Returns the accepted MIME type for the request + # Returns the accepted MIME type for the request. def accepts header = @env['HTTP_ACCEPT'].to_s.strip @@ -123,7 +125,7 @@ module ActionController not_modified?(response.last_modified) || etag_matches?(response.etag) end - # Returns the Mime type for the format used in the request. + # Returns the Mime type for the \format used in the request. # # GET /posts/5.xml | request.format => Mime::XML # GET /posts/5.xhtml | request.format => Mime::HTML @@ -142,8 +144,8 @@ module ActionController end - # Sets the format by string extension, which can be used to force custom formats that are not controlled by the extension. - # Example: + # Sets the \format by string extension, which can be used to force custom formats + # that are not controlled by the extension. # # class ApplicationController < ActionController::Base # before_filter :adjust_format_for_iphone @@ -159,7 +161,7 @@ module ActionController end # Returns a symbolized version of the <tt>:format</tt> parameter of the request. - # If no format is given it returns <tt>:js</tt>for AJAX requests and <tt>:html</tt> + # If no \format is given it returns <tt>:js</tt>for Ajax requests and <tt>:html</tt> # otherwise. def template_format parameter_format = parameters[:format] @@ -190,7 +192,7 @@ module ActionController # the right-hand-side of X-Forwarded-For TRUSTED_PROXIES = /^127\.0\.0\.1$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i - # Determine originating IP address. REMOTE_ADDR is the standard + # Determines 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 if # REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma- @@ -237,13 +239,13 @@ EOM memoize :server_software - # Returns the complete URL used for this request + # Returns the complete URL used for this request. def url protocol + host_with_port + request_uri end memoize :url - # Return 'https://' if this is an SSL request and 'http://' otherwise. + # Returns 'https://' if this is an SSL request and 'http://' otherwise. def protocol ssl? ? 'https://' : 'http://' end @@ -254,6 +256,7 @@ EOM @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https' end + # Returns the \host for this request, such as "example.com". def raw_host_with_port if forwarded = env["HTTP_X_FORWARDED_HOST"] forwarded.split(/,\s?/).last @@ -268,8 +271,8 @@ EOM end memoize :host - # Returns a host:port string for this request, such as example.com or - # example.com:8080. + # Returns a \host:\port string for this request, such as "example.com" or + # "example.com:8080". def host_with_port "#{host}#{port_string}" end @@ -285,7 +288,7 @@ EOM end memoize :port - # Returns the standard port number for this request's protocol + # Returns the standard \port number for this request's protocol. def standard_port case protocol when 'https://' then 443 @@ -293,13 +296,13 @@ EOM end end - # Returns a port suffix like ":8080" if the port number of this request - # is not the default HTTP port 80 or HTTPS port 443. + # Returns a \port suffix like ":8080" if the \port number of this request + # is not the default HTTP \port 80 or HTTPS \port 443. def port_string port == standard_port ? '' : ":#{port}" end - # Returns the domain part of a host, such as rubyonrails.org in "www.rubyonrails.org". You can specify + # 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) return nil unless named_host?(host) @@ -307,8 +310,9 @@ EOM 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"] + # Returns all the \subdomains as an array, so <tt>["dev", "www"]</tt> would be + # returned for "dev.www.rubyonrails.org". You can specify a different <tt>tld_length</tt>, + # such as 2 to catch <tt>["www"]</tt> instead of <tt>["www", "rubyonrails"]</tt> # in "www.rubyonrails.co.uk". def subdomains(tld_length = 1) return [] unless named_host?(host) @@ -316,7 +320,7 @@ EOM parts[0..-(tld_length+2)] end - # Return the query string, accounting for server idiosyncrasies. + # Returns the query string, accounting for server idiosyncrasies. def query_string if uri = @env['REQUEST_URI'] uri.split('?', 2)[1] || '' @@ -326,7 +330,7 @@ EOM end memoize :query_string - # Return the request URI, accounting for server idiosyncrasies. + # Returns the request URI, accounting for server idiosyncrasies. # WEBrick includes the full URL. IIS leaves REQUEST_URI blank. def request_uri if uri = @env['REQUEST_URI'] @@ -352,7 +356,8 @@ EOM end memoize :request_uri - # Returns the interpreted path to requested resource after all the installation directory of this application was taken into account + # Returns the interpreted \path to requested resource after all the installation + # directory of this application was taken into account. def path path = (uri = request_uri) ? uri.split('?').first.to_s : '' @@ -362,7 +367,7 @@ EOM end memoize :path - # Read the request body. This is useful for web services that need to + # Read the request \body. This is useful for web services that need to # work with raw requests directly. def raw_post unless env.include? 'RAW_POST_DATA' @@ -372,7 +377,7 @@ EOM env['RAW_POST_DATA'] end - # Returns both GET and POST parameters in a single hash. + # Returns both GET and POST \parameters in a single hash. def parameters @parameters ||= request_parameters.merge(query_parameters).update(path_parameters).with_indifferent_access end @@ -382,17 +387,17 @@ EOM @symbolized_path_parameters = @parameters = nil end - # The same as <tt>path_parameters</tt> with explicitly symbolized keys + # The same as <tt>path_parameters</tt> with explicitly symbolized keys. def symbolized_path_parameters @symbolized_path_parameters ||= path_parameters.symbolize_keys end - # Returns a hash with the parameters used to form the path of the request. - # Returned hash keys are strings. See <tt>symbolized_path_parameters</tt> for symbolized keys. - # - # Example: + # Returns a hash with the \parameters used to form the \path of the request. + # Returned hash keys are strings: # # {'action' => 'my_action', 'controller' => 'my_controller'} + # + # See <tt>symbolized_path_parameters</tt> for symbolized keys. def path_parameters @path_parameters ||= {} end |