Class: Rack::Request

Inherits:
Object
  • Object
show all
Includes:
Env, Helpers
Defined in:
lib/rack/request.rb

Overview

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

Defined Under Namespace

Modules: Env, Helpers

Constant Summary collapse

ALLOWED_SCHEMES =
%w(https http wss ws).freeze

Constants included from Helpers

Helpers::DEFAULT_PORTS, Helpers::FORM_DATA_MEDIA_TYPES, Helpers::HTTP_FORWARDED, Helpers::HTTP_X_FORWARDED_FOR, Helpers::HTTP_X_FORWARDED_HOST, Helpers::HTTP_X_FORWARDED_PORT, Helpers::HTTP_X_FORWARDED_PROTO, Helpers::HTTP_X_FORWARDED_SCHEME, Helpers::HTTP_X_FORWARDED_SSL, Helpers::PARSEABLE_DATA_MEDIA_TYPES

Class Attribute Summary collapse

Attributes included from Env

#env

Instance Method Summary collapse

Methods included from Helpers

#GET, #POST, #accept_encoding, #accept_language, #authority, #base_url, #body, #content_charset, #content_length, #content_type, #cookies, #delete?, #form_data?, #forwarded_authority, #forwarded_for, #forwarded_port, #fullpath, #get?, #head?, #host, #host_authority, #host_with_port, #hostname, #ip, #link?, #logger, #media_type, #media_type_params, #options?, #parseable_data?, #patch?, #path, #path_info, #path_info=, #port, #post?, #put?, #query_string, #referer, #request_method, #scheme, #script_name, #script_name=, #server_authority, #server_name, #server_port, #session, #session_options, #ssl?, #trace?, #trusted_proxy?, #unlink?, #url, #user_agent, #xhr?

Methods included from Env

#add_header, #delete_header, #each_header, #fetch_header, #get_header, #has_header?, #initialize_copy, #set_header

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.



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

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

Class Attribute Details

.forwarded_priorityObject

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.



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

def forwarded_priority
  @forwarded_priority
end

.ip_filterObject

Returns the value of attribute ip_filter.



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

def ip_filter
  @ip_filter
end

.x_forwarded_proto_priorityObject

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.



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

def x_forwarded_proto_priority
  @x_forwarded_proto_priority
end

Instance Method Details

#delete_param(k) ⇒ Object



76
77
78
79
80
# File 'lib/rack/request.rb', line 76

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

#paramsObject



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

def params
  @params ||= super
end

#update_param(k, v) ⇒ Object



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

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