actionpack 4.2.10 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +553 -401
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -3
- data/lib/abstract_controller/base.rb +28 -38
- data/lib/{action_controller → abstract_controller}/caching/fragments.rb +51 -11
- data/lib/abstract_controller/caching.rb +62 -0
- data/lib/abstract_controller/callbacks.rb +52 -19
- data/lib/abstract_controller/collector.rb +4 -9
- data/lib/abstract_controller/error.rb +4 -0
- data/lib/abstract_controller/helpers.rb +4 -3
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -2
- data/lib/abstract_controller/rendering.rb +28 -18
- data/lib/abstract_controller/translation.rb +8 -7
- data/lib/abstract_controller.rb +6 -2
- data/lib/action_controller/api/api_rendering.rb +14 -0
- data/lib/action_controller/api.rb +147 -0
- data/lib/action_controller/base.rb +10 -13
- data/lib/action_controller/caching.rb +13 -58
- data/lib/action_controller/form_builder.rb +48 -0
- data/lib/action_controller/log_subscriber.rb +3 -10
- data/lib/action_controller/metal/basic_implicit_render.rb +11 -0
- data/lib/action_controller/metal/conditional_get.rb +106 -34
- data/lib/action_controller/metal/cookies.rb +1 -3
- data/lib/action_controller/metal/data_streaming.rb +11 -32
- data/lib/action_controller/metal/etag_with_template_digest.rb +1 -1
- data/lib/action_controller/metal/exceptions.rb +11 -6
- data/lib/action_controller/metal/force_ssl.rb +10 -10
- data/lib/action_controller/metal/head.rb +14 -8
- data/lib/action_controller/metal/helpers.rb +15 -6
- data/lib/action_controller/metal/http_authentication.rb +44 -35
- data/lib/action_controller/metal/implicit_render.rb +61 -6
- data/lib/action_controller/metal/instrumentation.rb +5 -5
- data/lib/action_controller/metal/live.rb +66 -88
- data/lib/action_controller/metal/mime_responds.rb +27 -42
- data/lib/action_controller/metal/params_wrapper.rb +8 -8
- data/lib/action_controller/metal/redirecting.rb +32 -9
- data/lib/action_controller/metal/renderers.rb +85 -40
- data/lib/action_controller/metal/rendering.rb +38 -6
- data/lib/action_controller/metal/request_forgery_protection.rb +126 -48
- data/lib/action_controller/metal/rescue.rb +3 -12
- data/lib/action_controller/metal/streaming.rb +4 -4
- data/lib/action_controller/metal/strong_parameters.rb +293 -90
- data/lib/action_controller/metal/testing.rb +1 -12
- data/lib/action_controller/metal/url_for.rb +12 -5
- data/lib/action_controller/metal.rb +88 -63
- data/lib/action_controller/renderer.rb +111 -0
- data/lib/action_controller/template_assertions.rb +9 -0
- data/lib/action_controller/test_case.rb +288 -368
- data/lib/action_controller.rb +12 -9
- data/lib/action_dispatch/http/cache.rb +73 -34
- data/lib/action_dispatch/http/filter_parameters.rb +15 -11
- data/lib/action_dispatch/http/filter_redirect.rb +7 -8
- data/lib/action_dispatch/http/headers.rb +44 -13
- data/lib/action_dispatch/http/mime_negotiation.rb +41 -23
- data/lib/action_dispatch/http/mime_type.rb +126 -90
- data/lib/action_dispatch/http/mime_types.rb +3 -4
- data/lib/action_dispatch/http/parameter_filter.rb +18 -8
- data/lib/action_dispatch/http/parameters.rb +54 -41
- data/lib/action_dispatch/http/request.rb +149 -82
- data/lib/action_dispatch/http/response.rb +206 -102
- data/lib/action_dispatch/http/url.rb +117 -8
- data/lib/action_dispatch/journey/formatter.rb +39 -28
- data/lib/action_dispatch/journey/gtg/transition_table.rb +1 -1
- data/lib/action_dispatch/journey/nfa/dot.rb +0 -2
- data/lib/action_dispatch/journey/nfa/transition_table.rb +1 -46
- data/lib/action_dispatch/journey/nodes/node.rb +14 -4
- data/lib/action_dispatch/journey/parser_extras.rb +4 -0
- data/lib/action_dispatch/journey/path/pattern.rb +38 -42
- data/lib/action_dispatch/journey/route.rb +74 -19
- data/lib/action_dispatch/journey/router/utils.rb +5 -5
- data/lib/action_dispatch/journey/router.rb +5 -9
- data/lib/action_dispatch/journey/routes.rb +14 -15
- data/lib/action_dispatch/journey/visitors.rb +86 -43
- data/lib/action_dispatch/middleware/callbacks.rb +10 -1
- data/lib/action_dispatch/middleware/cookies.rb +189 -135
- data/lib/action_dispatch/middleware/debug_exceptions.rb +124 -49
- data/lib/action_dispatch/middleware/exception_wrapper.rb +21 -21
- data/lib/action_dispatch/middleware/executor.rb +19 -0
- data/lib/action_dispatch/middleware/flash.rb +66 -45
- data/lib/action_dispatch/middleware/params_parser.rb +32 -46
- data/lib/action_dispatch/middleware/public_exceptions.rb +2 -2
- data/lib/action_dispatch/middleware/reloader.rb +14 -58
- data/lib/action_dispatch/middleware/remote_ip.rb +29 -19
- data/lib/action_dispatch/middleware/request_id.rb +11 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +23 -11
- data/lib/action_dispatch/middleware/session/cache_store.rb +9 -6
- data/lib/action_dispatch/middleware/session/cookie_store.rb +30 -24
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +4 -0
- data/lib/action_dispatch/middleware/show_exceptions.rb +11 -9
- data/lib/action_dispatch/middleware/ssl.rb +115 -36
- data/lib/action_dispatch/middleware/stack.rb +44 -40
- data/lib/action_dispatch/middleware/static.rb +51 -35
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +2 -14
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +59 -63
- data/lib/action_dispatch/railtie.rb +2 -2
- data/lib/action_dispatch/request/session.rb +69 -33
- data/lib/action_dispatch/request/utils.rb +51 -19
- data/lib/action_dispatch/routing/inspector.rb +32 -43
- data/lib/action_dispatch/routing/mapper.rb +491 -338
- data/lib/action_dispatch/routing/polymorphic_routes.rb +8 -14
- data/lib/action_dispatch/routing/redirection.rb +3 -3
- data/lib/action_dispatch/routing/route_set.rb +145 -238
- data/lib/action_dispatch/routing/url_for.rb +27 -10
- data/lib/action_dispatch/routing.rb +17 -13
- data/lib/action_dispatch/testing/assertion_response.rb +45 -0
- data/lib/action_dispatch/testing/assertions/response.rb +38 -20
- data/lib/action_dispatch/testing/assertions/routing.rb +11 -10
- data/lib/action_dispatch/testing/assertions.rb +1 -1
- data/lib/action_dispatch/testing/integration.rb +368 -97
- data/lib/action_dispatch/testing/test_process.rb +5 -6
- data/lib/action_dispatch/testing/test_request.rb +22 -31
- data/lib/action_dispatch/testing/test_response.rb +7 -4
- data/lib/action_dispatch.rb +3 -1
- data/lib/action_pack/gem_version.rb +3 -3
- data/lib/action_pack.rb +1 -1
- metadata +30 -34
- data/lib/action_controller/metal/hide_actions.rb +0 -40
- data/lib/action_controller/metal/rack_delegation.rb +0 -32
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/model_naming.rb +0 -12
- data/lib/action_dispatch/journey/backwards.rb +0 -5
- data/lib/action_dispatch/journey/router/strexp.rb +0 -27
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
- /data/lib/action_dispatch/middleware/templates/rescues/{_source.erb → _source.html.erb} +0 -0
|
@@ -13,12 +13,14 @@ require 'action_dispatch/http/url'
|
|
|
13
13
|
require 'active_support/core_ext/array/conversions'
|
|
14
14
|
|
|
15
15
|
module ActionDispatch
|
|
16
|
-
class Request
|
|
16
|
+
class Request
|
|
17
|
+
include Rack::Request::Helpers
|
|
17
18
|
include ActionDispatch::Http::Cache::Request
|
|
18
19
|
include ActionDispatch::Http::MimeNegotiation
|
|
19
20
|
include ActionDispatch::Http::Parameters
|
|
20
21
|
include ActionDispatch::Http::FilterParameters
|
|
21
22
|
include ActionDispatch::Http::URL
|
|
23
|
+
include Rack::Request::Env
|
|
22
24
|
|
|
23
25
|
autoload :Session, 'action_dispatch/request/session'
|
|
24
26
|
autoload :Utils, 'action_dispatch/request/utils'
|
|
@@ -29,19 +31,28 @@ module ActionDispatch
|
|
|
29
31
|
PATH_TRANSLATED REMOTE_HOST
|
|
30
32
|
REMOTE_IDENT REMOTE_USER REMOTE_ADDR
|
|
31
33
|
SERVER_NAME SERVER_PROTOCOL
|
|
34
|
+
ORIGINAL_SCRIPT_NAME
|
|
32
35
|
|
|
33
36
|
HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
|
|
34
37
|
HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM
|
|
35
|
-
HTTP_NEGOTIATE HTTP_PRAGMA
|
|
38
|
+
HTTP_NEGOTIATE HTTP_PRAGMA HTTP_CLIENT_IP
|
|
39
|
+
HTTP_X_FORWARDED_FOR HTTP_ORIGIN HTTP_VERSION
|
|
40
|
+
HTTP_X_CSRF_TOKEN HTTP_X_REQUEST_ID HTTP_X_FORWARDED_HOST
|
|
41
|
+
SERVER_ADDR
|
|
42
|
+
].freeze
|
|
36
43
|
|
|
37
44
|
ENV_METHODS.each do |env|
|
|
38
45
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
|
39
46
|
def #{env.sub(/^HTTP_/n, '').downcase} # def accept_charset
|
|
40
|
-
|
|
47
|
+
get_header "#{env}".freeze # get_header "HTTP_ACCEPT_CHARSET".freeze
|
|
41
48
|
end # end
|
|
42
49
|
METHOD
|
|
43
50
|
end
|
|
44
51
|
|
|
52
|
+
def self.empty
|
|
53
|
+
new({})
|
|
54
|
+
end
|
|
55
|
+
|
|
45
56
|
def initialize(env)
|
|
46
57
|
super
|
|
47
58
|
@method = nil
|
|
@@ -50,7 +61,9 @@ module ActionDispatch
|
|
|
50
61
|
@original_fullpath = nil
|
|
51
62
|
@fullpath = nil
|
|
52
63
|
@ip = nil
|
|
53
|
-
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def commit_cookie_jar! # :nodoc:
|
|
54
67
|
end
|
|
55
68
|
|
|
56
69
|
def check_path_parameters!
|
|
@@ -59,13 +72,32 @@ module ActionDispatch
|
|
|
59
72
|
path_parameters.each do |key, value|
|
|
60
73
|
next unless value.respond_to?(:valid_encoding?)
|
|
61
74
|
unless value.valid_encoding?
|
|
62
|
-
raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}"
|
|
75
|
+
raise ActionController::BadRequest, "Invalid parameter encoding: #{key} => #{value.inspect}"
|
|
63
76
|
end
|
|
64
77
|
end
|
|
65
78
|
end
|
|
66
79
|
|
|
80
|
+
PASS_NOT_FOUND = Class.new { # :nodoc:
|
|
81
|
+
def self.action(_); self; end
|
|
82
|
+
def self.call(_); [404, {'X-Cascade' => 'pass'}, []]; end
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
def controller_class
|
|
86
|
+
check_path_parameters!
|
|
87
|
+
params = path_parameters
|
|
88
|
+
|
|
89
|
+
if params.key?(:controller)
|
|
90
|
+
controller_param = params[:controller].underscore
|
|
91
|
+
params[:action] ||= 'index'
|
|
92
|
+
const_name = "#{controller_param.camelize}Controller"
|
|
93
|
+
ActiveSupport::Dependencies.constantize(const_name)
|
|
94
|
+
else
|
|
95
|
+
PASS_NOT_FOUND
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
67
99
|
def key?(key)
|
|
68
|
-
|
|
100
|
+
has_header? key
|
|
69
101
|
end
|
|
70
102
|
|
|
71
103
|
# List of HTTP request methods from the following RFCs:
|
|
@@ -102,15 +134,50 @@ module ActionDispatch
|
|
|
102
134
|
# the application should use), this \method returns the overridden
|
|
103
135
|
# value, not the original.
|
|
104
136
|
def request_method
|
|
105
|
-
@request_method ||= check_method(
|
|
137
|
+
@request_method ||= check_method(super)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def routes # :nodoc:
|
|
141
|
+
get_header("action_dispatch.routes".freeze)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def routes=(routes) # :nodoc:
|
|
145
|
+
set_header("action_dispatch.routes".freeze, routes)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def engine_script_name(_routes) # :nodoc:
|
|
149
|
+
get_header(_routes.env_key)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def engine_script_name=(name) # :nodoc:
|
|
153
|
+
set_header(routes.env_key, name.dup)
|
|
106
154
|
end
|
|
107
155
|
|
|
108
156
|
def request_method=(request_method) #:nodoc:
|
|
109
157
|
if check_method(request_method)
|
|
110
|
-
@request_method =
|
|
158
|
+
@request_method = set_header("REQUEST_METHOD", request_method)
|
|
111
159
|
end
|
|
112
160
|
end
|
|
113
161
|
|
|
162
|
+
def controller_instance # :nodoc:
|
|
163
|
+
get_header('action_controller.instance'.freeze)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def controller_instance=(controller) # :nodoc:
|
|
167
|
+
set_header('action_controller.instance'.freeze, controller)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def http_auth_salt
|
|
171
|
+
get_header "action_dispatch.http_auth_salt"
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def show_exceptions? # :nodoc:
|
|
175
|
+
# We're treating `nil` as "unset", and we want the default setting to be
|
|
176
|
+
# `true`. This logic should be extracted to `env_config` and calculated
|
|
177
|
+
# once.
|
|
178
|
+
!(get_header('action_dispatch.show_exceptions'.freeze) == false)
|
|
179
|
+
end
|
|
180
|
+
|
|
114
181
|
# Returns a symbol form of the #request_method
|
|
115
182
|
def request_method_symbol
|
|
116
183
|
HTTP_METHOD_LOOKUP[request_method]
|
|
@@ -120,7 +187,7 @@ module ActionDispatch
|
|
|
120
187
|
# even if it was overridden by middleware. See #request_method for
|
|
121
188
|
# more information.
|
|
122
189
|
def method
|
|
123
|
-
@method ||= check_method(
|
|
190
|
+
@method ||= check_method(get_header("rack.methodoverride.original_method") || get_header('REQUEST_METHOD'))
|
|
124
191
|
end
|
|
125
192
|
|
|
126
193
|
# Returns a symbol form of the #method
|
|
@@ -128,47 +195,11 @@ module ActionDispatch
|
|
|
128
195
|
HTTP_METHOD_LOOKUP[method]
|
|
129
196
|
end
|
|
130
197
|
|
|
131
|
-
# Is this a GET (or HEAD) request?
|
|
132
|
-
# Equivalent to <tt>request.request_method_symbol == :get</tt>.
|
|
133
|
-
def get?
|
|
134
|
-
HTTP_METHOD_LOOKUP[request_method] == :get
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# Is this a POST request?
|
|
138
|
-
# Equivalent to <tt>request.request_method_symbol == :post</tt>.
|
|
139
|
-
def post?
|
|
140
|
-
HTTP_METHOD_LOOKUP[request_method] == :post
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# Is this a PATCH request?
|
|
144
|
-
# Equivalent to <tt>request.request_method == :patch</tt>.
|
|
145
|
-
def patch?
|
|
146
|
-
HTTP_METHOD_LOOKUP[request_method] == :patch
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
# Is this a PUT request?
|
|
150
|
-
# Equivalent to <tt>request.request_method_symbol == :put</tt>.
|
|
151
|
-
def put?
|
|
152
|
-
HTTP_METHOD_LOOKUP[request_method] == :put
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
# Is this a DELETE request?
|
|
156
|
-
# Equivalent to <tt>request.request_method_symbol == :delete</tt>.
|
|
157
|
-
def delete?
|
|
158
|
-
HTTP_METHOD_LOOKUP[request_method] == :delete
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
# Is this a HEAD request?
|
|
162
|
-
# Equivalent to <tt>request.request_method_symbol == :head</tt>.
|
|
163
|
-
def head?
|
|
164
|
-
HTTP_METHOD_LOOKUP[request_method] == :head
|
|
165
|
-
end
|
|
166
|
-
|
|
167
198
|
# Provides access to the request's HTTP headers, for example:
|
|
168
199
|
#
|
|
169
200
|
# request.headers["Content-Type"] # => "text/plain"
|
|
170
201
|
def headers
|
|
171
|
-
Http::Headers.new(
|
|
202
|
+
@headers ||= Http::Headers.new(self)
|
|
172
203
|
end
|
|
173
204
|
|
|
174
205
|
# Returns a +String+ with the last requested path including their params.
|
|
@@ -179,7 +210,7 @@ module ActionDispatch
|
|
|
179
210
|
# # get '/foo?bar'
|
|
180
211
|
# request.original_fullpath # => '/foo?bar'
|
|
181
212
|
def original_fullpath
|
|
182
|
-
@original_fullpath ||= (
|
|
213
|
+
@original_fullpath ||= (get_header("ORIGINAL_FULLPATH") || fullpath)
|
|
183
214
|
end
|
|
184
215
|
|
|
185
216
|
# Returns the +String+ full path including params of the last URL requested.
|
|
@@ -218,62 +249,84 @@ module ActionDispatch
|
|
|
218
249
|
# (case-insensitive), which may need to be manually added depending on the
|
|
219
250
|
# choice of JavaScript libraries and frameworks.
|
|
220
251
|
def xml_http_request?
|
|
221
|
-
|
|
252
|
+
get_header('HTTP_X_REQUESTED_WITH') =~ /XMLHttpRequest/i
|
|
222
253
|
end
|
|
223
254
|
alias :xhr? :xml_http_request?
|
|
224
255
|
|
|
256
|
+
# Returns the IP address of client as a +String+.
|
|
225
257
|
def ip
|
|
226
258
|
@ip ||= super
|
|
227
259
|
end
|
|
228
260
|
|
|
229
|
-
#
|
|
261
|
+
# Returns the IP address of client as a +String+,
|
|
262
|
+
# usually set by the RemoteIp middleware.
|
|
230
263
|
def remote_ip
|
|
231
|
-
@remote_ip ||= (
|
|
264
|
+
@remote_ip ||= (get_header("action_dispatch.remote_ip") || ip).to_s
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def remote_ip=(remote_ip)
|
|
268
|
+
set_header "action_dispatch.remote_ip".freeze, remote_ip
|
|
232
269
|
end
|
|
233
270
|
|
|
271
|
+
ACTION_DISPATCH_REQUEST_ID = "action_dispatch.request_id".freeze # :nodoc:
|
|
272
|
+
|
|
234
273
|
# Returns the unique request id, which is based on either the X-Request-Id header that can
|
|
235
274
|
# be generated by a firewall, load balancer, or web server or by the RequestId middleware
|
|
236
275
|
# (which sets the action_dispatch.request_id environment variable).
|
|
237
276
|
#
|
|
238
277
|
# This unique ID is useful for tracing a request from end-to-end as part of logging or debugging.
|
|
239
278
|
# This relies on the rack variable set by the ActionDispatch::RequestId middleware.
|
|
240
|
-
def
|
|
241
|
-
|
|
279
|
+
def request_id
|
|
280
|
+
get_header ACTION_DISPATCH_REQUEST_ID
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def request_id=(id) # :nodoc:
|
|
284
|
+
set_header ACTION_DISPATCH_REQUEST_ID, id
|
|
242
285
|
end
|
|
243
286
|
|
|
287
|
+
alias_method :uuid, :request_id
|
|
288
|
+
|
|
244
289
|
# Returns the lowercase name of the HTTP server software.
|
|
245
290
|
def server_software
|
|
246
|
-
(
|
|
291
|
+
(get_header('SERVER_SOFTWARE') && /^([a-zA-Z]+)/ =~ get_header('SERVER_SOFTWARE')) ? $1.downcase : nil
|
|
247
292
|
end
|
|
248
293
|
|
|
249
294
|
# Read the request \body. This is useful for web services that need to
|
|
250
295
|
# work with raw requests directly.
|
|
251
296
|
def raw_post
|
|
252
|
-
unless
|
|
297
|
+
unless has_header? 'RAW_POST_DATA'
|
|
253
298
|
raw_post_body = body
|
|
254
|
-
|
|
299
|
+
set_header('RAW_POST_DATA', raw_post_body.read(content_length))
|
|
255
300
|
raw_post_body.rewind if raw_post_body.respond_to?(:rewind)
|
|
256
301
|
end
|
|
257
|
-
|
|
302
|
+
get_header 'RAW_POST_DATA'
|
|
258
303
|
end
|
|
259
304
|
|
|
260
305
|
# The request body is an IO input stream. If the RAW_POST_DATA environment
|
|
261
306
|
# variable is already set, wrap it in a StringIO.
|
|
262
307
|
def body
|
|
263
|
-
if raw_post =
|
|
308
|
+
if raw_post = get_header('RAW_POST_DATA')
|
|
264
309
|
raw_post.force_encoding(Encoding::BINARY)
|
|
265
310
|
StringIO.new(raw_post)
|
|
266
311
|
else
|
|
267
|
-
|
|
312
|
+
body_stream
|
|
268
313
|
end
|
|
269
314
|
end
|
|
270
315
|
|
|
316
|
+
# Determine whether the request body contains form-data by checking
|
|
317
|
+
# the request Content-Type for one of the media-types:
|
|
318
|
+
# "application/x-www-form-urlencoded" or "multipart/form-data". The
|
|
319
|
+
# list of form-data media types can be modified through the
|
|
320
|
+
# +FORM_DATA_MEDIA_TYPES+ array.
|
|
321
|
+
#
|
|
322
|
+
# A request body is not assumed to contain form-data when no
|
|
323
|
+
# Content-Type header is provided and the request_method is POST.
|
|
271
324
|
def form_data?
|
|
272
|
-
FORM_DATA_MEDIA_TYPES.include?(
|
|
325
|
+
FORM_DATA_MEDIA_TYPES.include?(media_type)
|
|
273
326
|
end
|
|
274
327
|
|
|
275
328
|
def body_stream #:nodoc:
|
|
276
|
-
|
|
329
|
+
get_header('rack.input')
|
|
277
330
|
end
|
|
278
331
|
|
|
279
332
|
# TODO This should be broken apart into AD::Request::Session and probably
|
|
@@ -284,60 +337,74 @@ module ActionDispatch
|
|
|
284
337
|
else
|
|
285
338
|
self.session = {}
|
|
286
339
|
end
|
|
287
|
-
@env['action_dispatch.request.flash_hash'] = nil
|
|
288
340
|
end
|
|
289
341
|
|
|
290
342
|
def session=(session) #:nodoc:
|
|
291
|
-
Session.set
|
|
343
|
+
Session.set self, session
|
|
292
344
|
end
|
|
293
345
|
|
|
294
346
|
def session_options=(options)
|
|
295
|
-
Session::Options.set
|
|
347
|
+
Session::Options.set self, options
|
|
296
348
|
end
|
|
297
349
|
|
|
298
350
|
# Override Rack's GET method to support indifferent access
|
|
299
351
|
def GET
|
|
300
|
-
|
|
352
|
+
fetch_header("action_dispatch.request.query_parameters") do |k|
|
|
353
|
+
rack_query_params = super || {}
|
|
354
|
+
# Check for non UTF-8 parameter values, which would cause errors later
|
|
355
|
+
Request::Utils.check_param_encoding(rack_query_params)
|
|
356
|
+
set_header k, Request::Utils.normalize_encode_params(rack_query_params)
|
|
357
|
+
end
|
|
301
358
|
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
|
|
302
|
-
raise ActionController::BadRequest.new(
|
|
359
|
+
raise ActionController::BadRequest.new("Invalid query parameters: #{e.message}")
|
|
303
360
|
end
|
|
304
361
|
alias :query_parameters :GET
|
|
305
362
|
|
|
306
363
|
# Override Rack's POST method to support indifferent access
|
|
307
364
|
def POST
|
|
308
|
-
|
|
365
|
+
fetch_header("action_dispatch.request.request_parameters") do
|
|
366
|
+
pr = parse_formatted_parameters(params_parsers) do |params|
|
|
367
|
+
super || {}
|
|
368
|
+
end
|
|
369
|
+
self.request_parameters = Request::Utils.normalize_encode_params(pr)
|
|
370
|
+
end
|
|
371
|
+
rescue ParamsParser::ParseError # one of the parse strategies blew up
|
|
372
|
+
self.request_parameters = Request::Utils.normalize_encode_params(super || {})
|
|
373
|
+
raise
|
|
309
374
|
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
|
|
310
|
-
raise ActionController::BadRequest.new(
|
|
375
|
+
raise ActionController::BadRequest.new("Invalid request parameters: #{e.message}")
|
|
311
376
|
end
|
|
312
377
|
alias :request_parameters :POST
|
|
313
378
|
|
|
314
379
|
# Returns the authorization header regardless of whether it was specified directly or through one of the
|
|
315
380
|
# proxy alternatives.
|
|
316
381
|
def authorization
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
382
|
+
get_header('HTTP_AUTHORIZATION') ||
|
|
383
|
+
get_header('X-HTTP_AUTHORIZATION') ||
|
|
384
|
+
get_header('X_HTTP_AUTHORIZATION') ||
|
|
385
|
+
get_header('REDIRECT_X_HTTP_AUTHORIZATION')
|
|
321
386
|
end
|
|
322
387
|
|
|
323
|
-
# True if the request came from localhost, 127.0.0.1.
|
|
388
|
+
# True if the request came from localhost, 127.0.0.1, or ::1.
|
|
324
389
|
def local?
|
|
325
390
|
LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
|
|
326
391
|
end
|
|
327
392
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
)
|
|
393
|
+
def request_parameters=(params)
|
|
394
|
+
raise if params.nil?
|
|
395
|
+
set_header("action_dispatch.request.request_parameters".freeze, params)
|
|
396
|
+
end
|
|
333
397
|
|
|
334
|
-
|
|
398
|
+
def logger
|
|
399
|
+
get_header("action_dispatch.logger".freeze)
|
|
335
400
|
end
|
|
336
401
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
402
|
+
def commit_flash
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
def ssl?
|
|
406
|
+
super || scheme == 'wss'.freeze
|
|
407
|
+
end
|
|
341
408
|
|
|
342
409
|
private
|
|
343
410
|
def check_method(name)
|