Rack::Request
Which IP addresses are “trusted proxies” that can be stripped from the right-hand-side of X-Forwarded-For
Override Rack’s GET method to support indifferent access
# File lib/action_dispatch/http/request.rb, line 216
216: def GET
217: @env["action_dispatch.request.query_parameters"] ||= normalize_parameters(super)
218: end
Override Rack’s POST method to support indifferent access
# File lib/action_dispatch/http/request.rb, line 222
222: def POST
223: @env["action_dispatch.request.request_parameters"] ||= normalize_parameters(super)
224: end
The request body is an IO input stream. If the RAW_POST_DATA environment variable is already set, wrap it in a StringIO.
# File lib/action_dispatch/http/request.rb, line 182
182: def body
183: if raw_post = @env['RAW_POST_DATA']
184: raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
185: StringIO.new(raw_post)
186: else
187: @env['rack.input']
188: end
189: end
Returns the content length of the request as an integer.
# File lib/action_dispatch/http/request.rb, line 135
135: def content_length
136: super.to_i
137: end
Is this a DELETE request? Equivalent to request.request_method == :delete.
# File lib/action_dispatch/http/request.rb, line 105
105: def delete?
106: HTTP_METHOD_LOOKUP[request_method] == :delete
107: end
Access the contents of the flash. Use flash["notice"] to read a notice you put there or flash["notice"] = "hello" to put a new one.
# File lib/action_dispatch/middleware/flash.rb, line 6 6: def flash 7: @env['action_dispatch.request.flash_hash'] ||= (session["flash"] || Flash::FlashHash.new) 8: end
# File lib/action_dispatch/http/request.rb, line 126
126: def forgery_whitelisted?
127: get? || xhr? || content_mime_type.nil? || !content_mime_type.verify_request?
128: end
# File lib/action_dispatch/http/request.rb, line 191
191: def form_data?
192: FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s)
193: end
# File lib/action_dispatch/http/request.rb, line 122
122: def fullpath
123: @fullpath ||= super
124: end
Is this a GET (or HEAD) request? Equivalent to request.request_method == :get.
# File lib/action_dispatch/http/request.rb, line 87
87: def get?
88: HTTP_METHOD_LOOKUP[request_method] == :get
89: end
Is this a HEAD request? Equivalent to request.method == :head.
# File lib/action_dispatch/http/request.rb, line 111
111: def head?
112: HTTP_METHOD_LOOKUP[method] == :head
113: end
Provides access to the request’s HTTP headers, for example:
request.headers["Content-Type"] # => "text/plain"
# File lib/action_dispatch/http/request.rb, line 118
118: def headers
119: Http::Headers.new(@env)
120: end
# File lib/action_dispatch/http/request.rb, line 147
147: def ip
148: @ip ||= super
149: end
# File lib/action_dispatch/http/request.rb, line 43
43: def key?(key)
44: @env.key?(key)
45: end
True if the request came from localhost, 127.0.0.1.
# File lib/action_dispatch/http/request.rb, line 238
238: def local?
239: LOCALHOST.any? { |local_ip| local_ip === remote_addr && local_ip === remote_ip }
240: end
# File lib/action_dispatch/http/request.rb, line 130
130: def media_type
131: content_mime_type.to_s
132: end
Returns the original value of the environment’s REQUEST_METHOD, even if it was overridden by middleware. See # for more information.
# File lib/action_dispatch/http/request.rb, line 72
72: def method
73: @method ||= begin
74: method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']
75: HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
76: method
77: end
78: end
Returns a symbol form of the #
# File lib/action_dispatch/http/request.rb, line 81
81: def method_symbol
82: HTTP_METHOD_LOOKUP[method]
83: end
Is this a POST request? Equivalent to request.request_method == :post.
# File lib/action_dispatch/http/request.rb, line 93
93: def post?
94: HTTP_METHOD_LOOKUP[request_method] == :post
95: end
Is this a PUT request? Equivalent to request.request_method == :put.
# File lib/action_dispatch/http/request.rb, line 99
99: def put?
100: HTTP_METHOD_LOOKUP[request_method] == :put
101: end
Read the request body. This is useful for web services that need to work with raw requests directly.
# File lib/action_dispatch/http/request.rb, line 172
172: def raw_post
173: unless @env.include? 'RAW_POST_DATA'
174: @env['RAW_POST_DATA'] = body.read(@env['CONTENT_LENGTH'].to_i)
175: body.rewind if body.respond_to?(:rewind)
176: end
177: @env['RAW_POST_DATA']
178: end
Determines originating IP address. REMOTE_ADDR is the standard but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or HTTP_X_FORWARDED_FOR are set by proxies so check for these if REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma- delimited list in the case of multiple chained proxies; the last address which is not trusted is the originating IP.
# File lib/action_dispatch/http/request.rb, line 161
161: def remote_ip
162: @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
163: end
Returns the HTTP method that the application should see. In the case where the method was overridden by a middleware (for instance, if a HEAD request was converted to a GET, or if a _method parameter was used to determine the method the application should use), this method returns the overridden value, not the original.
# File lib/action_dispatch/http/request.rb, line 56
56: def request_method
57: @request_method ||= begin
58: method = env["REQUEST_METHOD"]
59: HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
60: method
61: end
62: end
Returns a symbol form of the #
# File lib/action_dispatch/http/request.rb, line 65
65: def request_method_symbol
66: HTTP_METHOD_LOOKUP[request_method]
67: end
TODO This should be broken apart into AD::Request::Session and probably be included by the session middleware.
# File lib/action_dispatch/http/request.rb, line 201
201: def reset_session
202: session.destroy if session
203: self.session = {}
204: @env['action_dispatch.request.flash_hash'] = nil
205: end
Returns the lowercase name of the HTTP server software.
# File lib/action_dispatch/http/request.rb, line 166
166: def server_software
167: (@env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil
168: end
# File lib/action_dispatch/http/request.rb, line 211
211: def session_options=(options)
212: @env['rack.session.options'] = options
213: end
Returns true if the request’s “X-Requested-With” header contains “XMLHttpRequest”. (The Prototype Javascript library sends this header with every Ajax request.)
# File lib/action_dispatch/http/request.rb, line 142
142: def xml_http_request?
143: !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/)
144: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.