class ActionDispatch::Request
def GET
def GET @env["action_dispatch.request.query_parameters"] ||= Utils.deep_munge(normalize_encode_params(super || {})) rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise ActionController::BadRequest.new(:query, e) end
def POST
def POST @env["action_dispatch.request.request_parameters"] ||= Utils.deep_munge(normalize_encode_params(super || {})) rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e raise ActionController::BadRequest.new(:request, e) end
def authorization
Returns the authorization header regardless of whether it was specified directly or through one of the
def authorization @env['HTTP_AUTHORIZATION'] || @env['X-HTTP_AUTHORIZATION'] || @env['X_HTTP_AUTHORIZATION'] || @env['REDIRECT_X_HTTP_AUTHORIZATION'] end
def body
The request body is an IO input stream. If the RAW_POST_DATA environment
def body if raw_post = @env['RAW_POST_DATA'] raw_post.force_encoding(Encoding::BINARY) StringIO.new(raw_post) else @env['rack.input'] end end
def body_stream #:nodoc:
def body_stream #:nodoc: @env['rack.input'] end
def check_method(name)
def check_method(name) HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS[0...-1].join(', ')}, and #{HTTP_METHODS[-1]}") name end
def check_path_parameters!
def check_path_parameters! # If any of the path parameters has an invalid encoding then # raise since it's likely to trigger errors further on. path_parameters.each do |key, value| next unless value.respond_to?(:valid_encoding?) unless value.valid_encoding? raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}" end end end
def content_length
def content_length super.to_i end
def cookie_jar
def cookie_jar env['action_dispatch.cookies'] ||= Cookies::CookieJar.build(self) end
def deep_munge(hash)
def deep_munge(hash) ActiveSupport::Deprecation.warn( 'This method has been extracted into `ActionDispatch::Request::Utils.deep_munge`. Please start using that instead.' ) Utils.deep_munge(hash) end
def delete?
Is this a DELETE request?
def delete? HTTP_METHOD_LOOKUP[request_method] == :delete end
def flash
read a notice you put there or flash["notice"] = "hello"
Access the contents of the flash. Use flash["notice"] to
def flash @env[Flash::KEY] ||= Flash::FlashHash.from_session_value(session["flash"]) end
def form_data?
def form_data? FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s) end
def fullpath
# get "/articles?page=2"
request.fullpath # => "/articles"
# get "/articles"
Returns the +String+ full path including params of the last URL requested.
def fullpath @fullpath ||= super end
def get?
Is this a GET (or HEAD) request?
def get? HTTP_METHOD_LOOKUP[request_method] == :get end
def head?
Is this a HEAD request?
def head? HTTP_METHOD_LOOKUP[request_method] == :head end
def headers
Provides access to the request's HTTP headers, for example:
def headers Http::Headers.new(@env) end
def initialize(env)
def initialize(env) super @method = nil @request_method = nil @remote_ip = nil @original_fullpath = nil @fullpath = nil @ip = nil @uuid = nil end
def ip
def ip @ip ||= super end
def key?(key)
def key?(key) @env.key?(key) end
def local?
def local? LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip end
def media_type
# get "/articles"
The +String+ MIME type of the request.
def media_type content_mime_type.to_s end
def method
even if it was overridden by middleware. See #request_method for
Returns the original value of the environment's REQUEST_METHOD,
def method @method ||= check_method(env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']) end
def method_symbol
def method_symbol HTTP_METHOD_LOOKUP[method] end
def original_fullpath
# get '/foo?bar'
request.original_fullpath # => '/foo'
# get '/foo'
Returns a +String+ with the last requested path including their params.
def original_fullpath @original_fullpath ||= (env["ORIGINAL_FULLPATH"] || fullpath) end
def original_url
# get "/articles?page=2"
Returns the original request URL as a +String+.
def original_url base_url + original_fullpath end
def parse_query(qs)
def parse_query(qs) Utils.deep_munge(super) end
def patch?
Is this a PATCH request?
def patch? HTTP_METHOD_LOOKUP[request_method] == :patch end
def post?
Is this a POST request?
def post? HTTP_METHOD_LOOKUP[request_method] == :post end
def put?
Is this a PUT request?
def put? HTTP_METHOD_LOOKUP[request_method] == :put end
def raw_post
Read the request \body. This is useful for web services that need to
def raw_post unless @env.include? 'RAW_POST_DATA' raw_post_body = body @env['RAW_POST_DATA'] = raw_post_body.read(content_length) raw_post_body.rewind if raw_post_body.respond_to?(:rewind) end @env['RAW_POST_DATA'] end
def remote_ip
def remote_ip @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s end
def request_method
the application should use), this \method returns the overridden
or if a _method parameter was used to determine the \method
(for instance, if a HEAD request was converted to a GET,
In the case where the \method was overridden by a middleware
Returns the HTTP \method that the application should see.
def request_method @request_method ||= check_method(env["REQUEST_METHOD"]) end
def request_method=(request_method) #:nodoc:
def request_method=(request_method) #:nodoc: if check_method(request_method) @request_method = env["REQUEST_METHOD"] = request_method end end
def request_method_symbol
def request_method_symbol HTTP_METHOD_LOOKUP[request_method] end
def reset_session
TODO This should be broken apart into AD::Request::Session and probably
def reset_session if session && session.respond_to?(:destroy) session.destroy else self.session = {} end @env['action_dispatch.request.flash_hash'] = nil end
def server_software
def server_software (@env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil end
def session=(session) #:nodoc:
def session=(session) #:nodoc: Session.set @env, session end
def session_options=(options)
def session_options=(options) Session::Options.set @env, options end
def uuid
This unique ID is useful for tracing a request from end-to-end as part of logging or debugging.
(which sets the action_dispatch.request_id environment variable).
be generated by a firewall, load balancer, or web server or by the RequestId middleware
Returns the unique request id, which is based on either the X-Request-Id header that can
def uuid @uuid ||= env["action_dispatch.request_id"] end
def xml_http_request?
(case-insensitive), which may need to be manually added depending on the
Returns true if the "X-Requested-With" header contains "XMLHttpRequest"
def xml_http_request? @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i end