123456789_123456789_123456789_123456789_123456789_

Class: Rack::Request

Relationships & Source Files
Namespace Children
Modules:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Helpers, Env
Inherits: Object
Defined in: lib/rack/request.rb

Overview

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"]

Constant Summary

Helpers - Included

AUTHORITY, DEFAULT_PORTS, FORM_DATA_MEDIA_TYPES, FORWARDED_SCHEME_HEADERS, HTTP_FORWARDED, HTTP_X_FORWARDED_FOR, HTTP_X_FORWARDED_HOST, HTTP_X_FORWARDED_PORT, HTTP_X_FORWARDED_PROTO, HTTP_X_FORWARDED_SCHEME, HTTP_X_FORWARDED_SSL, PARSEABLE_DATA_MEDIA_TYPES

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

Helpers - Included

#delete?

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

#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”.

#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.

#link?

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

#options?

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

#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_info, #path_info=,
#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.

#script_name, #script_name=, #ssl?,
#trace?

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

#unlink?

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

#xhr?

Env - Included

#env

The environment of the request.

Instance Method Summary

Helpers - Included

#accept_encoding, #accept_language,
#authority

The authority of the incoming request as defined by RFC3976.

#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.

#content_length, #content_type, #cookies,
#delete_param

Destructively delete a parameter, whether it’s in GET or POST.

#forwarded_authority, #forwarded_for, #forwarded_port, #fullpath,
#GET

Returns the data received in the query string.

#host

Returns a formatted host, suitable for being used in a URI.

#host_authority

The HTTP_HOST header.

#host_with_port,
#hostname

Returns an address suitable for being to resolve to an address.

#ip, #logger,
#media_type

The media type (type/subtype) portion of the CONTENT_TYPE header without any media type parameters.

#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.

#params

The union of GET and POST data.

#path, #port,
#POST

Returns the data received in the request body.

#query_string,
#referer

the referer of the client.

#referrer

Alias for Helpers#referer.

#request_method, #scheme,
#server_authority

The authority as defined by the SERVER_NAME and SERVER_PORT variables.

#server_name, #server_port, #session, #session_options, #trusted_proxy?,
#update_param

Destructively update a parameter, whether it’s in GET and/or POST.

#url

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

#user_agent, #allowed_scheme, #default_session, #expand_param_pairs, #forwarded_priority, #forwarded_scheme,
#get_http_forwarded

Get an array of values set in the RFC 7239 Forwarded request header.

#parse_http_accept_header, #parse_multipart, #parse_query, #query_parser, #reject_trusted_ip_addresses, #split_authority, #split_header,
#wrap_ipv6

Assist with compatibility when processing X-Forwarded-For.

#x_forwarded_proto_priority

Env - Included

#add_header

Add a header that may have multiple values.

#delete_header

Delete a request specific value for name.

#each_header

Loops through each key / value pair in the request specific data.

#fetch_header

If a block is given, it yields to the block if the value hasn’t been set on the request.

#get_header

Get a request specific value for name.

#has_header?

Predicate method to test to see if name has been set as request specific data.

#initialize, #initialize_copy,
#set_header

Set a request specific value for name to ‘v`.

Constructor Details

.new(env) ⇒ Request

[ GitHub ]

  
# File 'lib/rack/request.rb', line 62

def initialize(env)
  @env = env
  @params = nil
end

Class Attribute Details

.forwarded_priority (rw)

The priority when checking forwarded headers. The default is [:forwarded, :x_forwarded], which means, check the Forwarded header first, followed by the appropriate X-Forwarded-* header. You can revert the priority by reversing the priority, or remove checking of either or both headers by removing elements from the array.

This should be set as appropriate in your environment based on what reverse proxies are in use. If you are not using reverse proxies, you should probably use an empty array.

[ GitHub ]

  
# File 'lib/rack/request.rb', line 31

attr_accessor :forwarded_priority

.ip_filter (rw)

[ GitHub ]

  
# File 'lib/rack/request.rb', line 18

attr_accessor :ip_filter

.x_forwarded_proto_priority (rw)

The priority when checking either the X-Forwarded-Proto or X-Forwarded-Scheme header for the forwarded protocol. The default is [:proto, :scheme], to try the X-Forwarded-Proto header before the X-Forwarded-Scheme header. ::Rack 2 had behavior similar to [:scheme, :proto]. You can remove either or both of the entries in array to ignore that respective header.

[ GitHub ]

  
# File 'lib/rack/request.rb', line 40

attr_accessor :x_forwarded_proto_priority

Instance Method Details

#delete_param(k)

[ GitHub ]

  
# File 'lib/rack/request.rb', line 76

def delete_param(k)
  v = super
  @params = nil
  v
end

#params

[ GitHub ]

  
# File 'lib/rack/request.rb', line 67

def params
  @params ||= super
end

#update_param(k, v)

[ GitHub ]

  
# File 'lib/rack/request.rb', line 71

def update_param(k, v)
  super
  @params = nil
end