Class | Rack::Request
In: | lib/rack/request.rb
Parent: | Object

Rack::Request provides a convenient interface to a Rack environment. It is stateless, the environment `env` passed to the constructor will be directly modified.

      req = Rack::Request.new(env)
      req.post?
      req.params["data"]

### Methods

GET POST [] []= accept_encoding accept_language base_url body content_charset content_length content_type cookies delete? delete_param form_data? fullpath get? head? host host_with_port ip link? logger media_type media_type_params new options? params parse_http_accept_header parse_multipart parse_query parseable_data? patch? path path_info path_info= port post? put? query_string referer referrer reject_trusted_ip_addresses request_method scheme script_name script_name= session session_options split_ip_addresses ssl? trace? trusted_proxy? unlink? update_param url user_agent values_at xhr?

### Constants

FORM_DATA_MEDIA_TYPES | = | [ 'application/x-www-form-urlencoded', 'multipart/form-data' |  | The set of form-data media-types. Requests that do not indicate one of the media types presents in this list will not be eligible for form-data / param parsing.
PARSEABLE_DATA_MEDIA_TYPES | = | [ 'multipart/related', 'multipart/mixed' |  | The set of media-types. Requests that do not indicate one of the media types presents in this list will not be eligible for param parsing like soap attachments or generic multiparts
DEFAULT_PORTS | = | { 'http' => 80, 'https' => 443, 'coffee' => 80 } |  | Default ports depending on scheme. Used to decide whether or not to include the port in a generated URI.

### Attributes

env | [R] | The environment of the request.

### Public Class methods

new(env)

### Public Instance methods

GET()

Returns the data received in the query string.

POST()

Returns the data received in the request body.

This method support both application/x-www-form-urlencoded and multipart/form-data.

[](key)

shortcut for request.params[key]

[]=(key, value)

shortcut for request.params[key] = value

Note that modifications will not be persisted in the env. Use update_param or delete_param if you want to destructively modify params.

accept_encoding()
accept_language()
base_url()
body()
content_charset()

The character set of the request body if a "charset" media type parameter was given, or nil if no "charset" was specified. Note that, per RFC2616, text/* media types that specify no explicit charset are to be considered ISO-8859-1.

content_length()
content_type()
cookies()
delete?()

Checks the HTTP request method (or verb) to see if it was of type DELETE

delete_param(k)

Destructively delete a parameter, whether it‘s in GET or POST. Returns the value of the deleted parameter.

If the parameter is in both GET and POST, the POST value takes precedence since that‘s how params works.

env is not touched.

form_data?()

Determine whether the request body contains form-data by checking the request Content-Type for one of the media-types: "application/x-www-form-urlencoded" or "multipart/form-data". The list of form-data media types can be modified through the `FORM_DATA_MEDIA_TYPES` array.

A request body is also assumed to contain form-data when no Content-Type header is provided and the request_method is POST.

fullpath()
get?()

Checks the HTTP request method (or verb) to see if it was of type GET

head?()

Checks the HTTP request method (or verb) to see if it was of type HEAD

host()
host_with_port()
ip()
link?()

Checks the HTTP request method (or verb) to see if it was of type LINK

logger()
media_type()

The media type (type/subtype) portion of the CONTENT_TYPE header without any media type parameters. e.g., when CONTENT_TYPE is "text/plain;charset=utf-8", the media-type is "text/plain".

For more information on the use of media types in HTTP, see: www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7

media_type_params()

The media type parameters provided in CONTENT_TYPE as a Hash, or an empty Hash if no CONTENT_TYPE or media-type parameters were provided. e.g., when the CONTENT_TYPE is "text/plain;charset=utf-8", this method responds with the following Hash:

      { 'charset' => 'utf-8' }

options?()

Checks the HTTP request method (or verb) to see if it was of type OPTIONS

params()

The union of GET and POST data.

Note that modifications will not be persisted in the env. Use update_param or delete_param if you want to destructively modify params.

parseable_data?()

Determine whether the request body contains data by checking the request media_type against registered parse-data media-types

patch?()

Checks the HTTP request method (or verb) to see if it was of type PATCH

path()
path_info()
path_info=(s)
port()
post?()

Checks the HTTP request method (or verb) to see if it was of type POST

put?()

Checks the HTTP request method (or verb) to see if it was of type PUT

query_string()
referer()

the referer of the client

referrer()

Alias for referer

request_method()
scheme()
script_name()
script_name=(s)
session()
session_options()
ssl?()
trace?()

Checks the HTTP request method (or verb) to see if it was of type TRACE

trusted_proxy?(ip)
unlink?()

Checks the HTTP request method (or verb) to see if it was of type UNLINK

update_param(k, v)

Destructively update a parameter, whether it‘s in GET and/or POST. Returns nil.

The parameter is updated wherever it was previous defined, so GET, POST, or both. If it wasn‘t previously defined, it‘s inserted into GET.

env is not touched.

url()

Tries to return a remake of the original request URL as a string.

user_agent()
values_at(*keys)

like Hash#values_at

xhr?()

### Protected Instance methods

parse_http_accept_header(header)
parse_multipart(env)
parse_query(qs)
reject_trusted_ip_addresses(ip_addresses)
split_ip_addresses(ip_addresses)

[Validate]