class ActionDispatch::Request
def self.new(env)
def self.new(env) if request = env["action_dispatch.request"] && request.instance_of?(self) return request end super end
def GET
def GET @env["action_dispatch.request.query_parameters"] ||= normalize_parameters(super) end
def POST
def POST @env["action_dispatch.request.request_parameters"] ||= normalize_parameters(super) 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) if raw_post.respond_to?(:force_encoding) StringIO.new(raw_post) else @env['rack.input'] end end
def body_stream #:nodoc:
def body_stream #:nodoc: @env['rack.input'] 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 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['action_dispatch.request.flash_hash'] ||= (session["flash"] || Flash::FlashHash.new) end
def forgery_whitelisted?
def forgery_whitelisted? get? end
def form_data?
def form_data? FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s) end
def fullpath
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[method] == :head end
def headers
Provides access to the request's HTTP headers, for example:
def headers Http::Headers.new(@env) end
def ip
def ip @ip ||= super end
def key?(key)
def key?(key) @env.key?(key) end
def local?
def local? LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip } end
def media_type
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 ||= begin method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD'] HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") method end end
def method_symbol
def method_symbol HTTP_METHOD_LOOKUP[method] 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' @env['RAW_POST_DATA'] = body.read(@env['CONTENT_LENGTH'].to_i) body.rewind if body.respond_to?(:rewind) end @env['RAW_POST_DATA'] end
def remote_ip
delimited list in the case of multiple chained proxies; the last
REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma-
HTTP_X_FORWARDED_FOR are set by proxies so check for these if
but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or
Determines originating IP address. REMOTE_ADDR is the standard
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 ||= begin method = env["REQUEST_METHOD"] HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") 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 session.destroy if session && session.respond_to?(:destroy) self.session = {} @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: @env['rack.session'] = session end
def session_options=(options)
def session_options=(options) @env['rack.session.options'] = options end
def xml_http_request?
"XMLHttpRequest". (The Prototype Javascript library sends this header with
Returns true if the request's "X-Requested-With" header contains
def xml_http_request? !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/i) end