actionpack 4.2.11.3 → 5.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +379 -462
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -3
- data/lib/abstract_controller.rb +0 -2
- data/lib/abstract_controller/base.rb +17 -32
- data/lib/abstract_controller/callbacks.rb +52 -19
- data/lib/abstract_controller/collector.rb +4 -9
- data/lib/abstract_controller/helpers.rb +2 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -2
- data/lib/abstract_controller/rendering.rb +27 -22
- data/lib/abstract_controller/translation.rb +8 -7
- data/lib/action_controller.rb +4 -3
- data/lib/action_controller/api.rb +146 -0
- data/lib/action_controller/base.rb +6 -10
- data/lib/action_controller/caching.rb +1 -3
- data/lib/action_controller/caching/fragments.rb +48 -3
- data/lib/action_controller/form_builder.rb +48 -0
- data/lib/action_controller/log_subscriber.rb +1 -10
- data/lib/action_controller/metal.rb +89 -62
- data/lib/action_controller/metal/basic_implicit_render.rb +11 -0
- data/lib/action_controller/metal/conditional_get.rb +65 -24
- data/lib/action_controller/metal/cookies.rb +0 -2
- data/lib/action_controller/metal/data_streaming.rb +2 -22
- 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 +6 -6
- data/lib/action_controller/metal/head.rb +14 -7
- data/lib/action_controller/metal/helpers.rb +9 -5
- data/lib/action_controller/metal/http_authentication.rb +37 -38
- data/lib/action_controller/metal/implicit_render.rb +23 -6
- data/lib/action_controller/metal/instrumentation.rb +0 -1
- data/lib/action_controller/metal/live.rb +17 -55
- data/lib/action_controller/metal/mime_responds.rb +17 -37
- 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 +10 -8
- data/lib/action_controller/metal/rendering.rb +38 -6
- data/lib/action_controller/metal/request_forgery_protection.rb +67 -35
- data/lib/action_controller/metal/rescue.rb +2 -4
- data/lib/action_controller/metal/streaming.rb +4 -4
- data/lib/action_controller/metal/strong_parameters.rb +231 -78
- data/lib/action_controller/metal/testing.rb +1 -12
- data/lib/action_controller/metal/url_for.rb +12 -5
- data/lib/action_controller/renderer.rb +111 -0
- data/lib/action_controller/template_assertions.rb +9 -0
- data/lib/action_controller/test_case.rb +267 -363
- data/lib/action_dispatch.rb +2 -1
- data/lib/action_dispatch/http/cache.rb +23 -26
- data/lib/action_dispatch/http/filter_parameters.rb +6 -8
- data/lib/action_dispatch/http/filter_redirect.rb +7 -8
- data/lib/action_dispatch/http/headers.rb +28 -11
- data/lib/action_dispatch/http/mime_negotiation.rb +40 -26
- data/lib/action_dispatch/http/mime_type.rb +92 -61
- data/lib/action_dispatch/http/mime_types.rb +1 -4
- data/lib/action_dispatch/http/parameter_filter.rb +18 -8
- data/lib/action_dispatch/http/parameters.rb +45 -41
- data/lib/action_dispatch/http/request.rb +146 -82
- data/lib/action_dispatch/http/response.rb +180 -99
- data/lib/action_dispatch/http/url.rb +117 -8
- data/lib/action_dispatch/journey/formatter.rb +34 -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 +37 -41
- data/lib/action_dispatch/journey/route.rb +71 -17
- data/lib/action_dispatch/journey/router.rb +5 -6
- data/lib/action_dispatch/journey/router/utils.rb +5 -5
- data/lib/action_dispatch/journey/routes.rb +14 -15
- data/lib/action_dispatch/journey/visitors.rb +86 -43
- data/lib/action_dispatch/middleware/cookies.rb +184 -135
- data/lib/action_dispatch/middleware/debug_exceptions.rb +115 -45
- data/lib/action_dispatch/middleware/exception_wrapper.rb +21 -20
- data/lib/action_dispatch/middleware/flash.rb +61 -45
- data/lib/action_dispatch/middleware/load_interlock.rb +21 -0
- data/lib/action_dispatch/middleware/params_parser.rb +30 -46
- data/lib/action_dispatch/middleware/public_exceptions.rb +2 -2
- data/lib/action_dispatch/middleware/reloader.rb +2 -4
- 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 +29 -23
- 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 +93 -36
- data/lib/action_dispatch/middleware/stack.rb +43 -48
- data/lib/action_dispatch/middleware/static.rb +52 -40
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +2 -14
- data/lib/action_dispatch/middleware/templates/rescues/{_source.erb → _source.html.erb} +0 -0
- 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 +0 -2
- data/lib/action_dispatch/request/session.rb +66 -34
- data/lib/action_dispatch/request/utils.rb +51 -19
- data/lib/action_dispatch/routing.rb +3 -8
- data/lib/action_dispatch/routing/inspector.rb +6 -30
- data/lib/action_dispatch/routing/mapper.rb +447 -322
- 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 +124 -227
- data/lib/action_dispatch/routing/url_for.rb +27 -10
- data/lib/action_dispatch/testing/assertions.rb +1 -1
- data/lib/action_dispatch/testing/assertions/response.rb +27 -9
- data/lib/action_dispatch/testing/assertions/routing.rb +9 -9
- data/lib/action_dispatch/testing/integration.rb +237 -76
- data/lib/action_dispatch/testing/test_process.rb +5 -5
- data/lib/action_dispatch/testing/test_request.rb +12 -21
- data/lib/action_dispatch/testing/test_response.rb +1 -4
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/gem_version.rb +4 -4
- metadata +26 -25
- 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/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
@@ -1,29 +1,37 @@
|
|
1
|
-
require 'set'
|
2
1
|
require 'singleton'
|
3
2
|
require 'active_support/core_ext/module/attribute_accessors'
|
4
3
|
require 'active_support/core_ext/string/starts_ends_with'
|
5
4
|
|
6
5
|
module Mime
|
7
|
-
class Mimes
|
8
|
-
|
9
|
-
|
6
|
+
class Mimes
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@mimes = []
|
11
|
+
@symbols = nil
|
10
12
|
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
def each
|
15
|
+
@mimes.each { |x| yield x }
|
16
|
+
end
|
17
|
+
|
18
|
+
def <<(type)
|
19
|
+
@mimes << type
|
20
|
+
@symbols = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_if
|
24
|
+
@mimes.delete_if { |x| yield x }.tap { @symbols = nil }
|
25
|
+
end
|
26
|
+
|
27
|
+
def symbols
|
28
|
+
@symbols ||= map(&:to_sym)
|
21
29
|
end
|
22
30
|
end
|
23
31
|
|
24
32
|
SET = Mimes.new
|
25
33
|
EXTENSION_LOOKUP = {}
|
26
|
-
LOOKUP = {}
|
34
|
+
LOOKUP = Hash.new { |h, k| h[k] = Type.new(k) unless k.blank? }
|
27
35
|
|
28
36
|
class << self
|
29
37
|
def [](type)
|
@@ -35,6 +43,32 @@ module Mime
|
|
35
43
|
return type if type.is_a?(Type)
|
36
44
|
EXTENSION_LOOKUP.fetch(type.to_s) { |k| yield k }
|
37
45
|
end
|
46
|
+
|
47
|
+
def const_missing(sym)
|
48
|
+
ext = sym.downcase
|
49
|
+
if Mime[ext]
|
50
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
51
|
+
Accessing mime types via constants is deprecated.
|
52
|
+
Please change `Mime::#{sym}` to `Mime[:#{ext}]`.
|
53
|
+
MSG
|
54
|
+
Mime[ext]
|
55
|
+
else
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def const_defined?(sym, inherit = true)
|
61
|
+
ext = sym.downcase
|
62
|
+
if Mime[ext]
|
63
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
64
|
+
Accessing mime types via constants is deprecated.
|
65
|
+
Please change `Mime.const_defined?(#{sym})` to `Mime[:#{ext}]`.
|
66
|
+
MSG
|
67
|
+
true
|
68
|
+
else
|
69
|
+
super
|
70
|
+
end
|
71
|
+
end
|
38
72
|
end
|
39
73
|
|
40
74
|
# Encapsulates the notion of a mime type. Can be used at render time, for example, with:
|
@@ -45,15 +79,12 @@ module Mime
|
|
45
79
|
#
|
46
80
|
# respond_to do |format|
|
47
81
|
# format.html
|
48
|
-
# format.ics { render
|
82
|
+
# format.ics { render body: @post.to_ics, mime_type: Mime::Type.lookup("text/calendar") }
|
49
83
|
# format.xml { render xml: @post }
|
50
84
|
# end
|
51
85
|
# end
|
52
86
|
# end
|
53
87
|
class Type
|
54
|
-
@@html_types = Set.new [:html, :all]
|
55
|
-
cattr_reader :html_types
|
56
|
-
|
57
88
|
attr_reader :symbol
|
58
89
|
|
59
90
|
@register_callbacks = []
|
@@ -66,7 +97,7 @@ module Mime
|
|
66
97
|
def initialize(index, name, q = nil)
|
67
98
|
@index = index
|
68
99
|
@name = name
|
69
|
-
q ||= 0.0 if @name ==
|
100
|
+
q ||= 0.0 if @name == '*/*'.freeze # default wildcard match to end of list
|
70
101
|
@q = ((q || 1.0).to_f * 100).to_i
|
71
102
|
end
|
72
103
|
|
@@ -91,7 +122,7 @@ module Mime
|
|
91
122
|
exchange_xml_items if app_xml_idx > text_xml_idx # make sure app_xml is ahead of text_xml in the list
|
92
123
|
delete_at(text_xml_idx) # delete text_xml from the list
|
93
124
|
elsif text_xml_idx
|
94
|
-
text_xml.name = Mime
|
125
|
+
text_xml.name = Mime[:xml].to_s
|
95
126
|
end
|
96
127
|
|
97
128
|
# Look for more specific XML-based types and sort them ahead of app/xml
|
@@ -120,7 +151,7 @@ module Mime
|
|
120
151
|
end
|
121
152
|
|
122
153
|
def app_xml_idx
|
123
|
-
@app_xml_idx ||= index(Mime
|
154
|
+
@app_xml_idx ||= index(Mime[:xml].to_s)
|
124
155
|
end
|
125
156
|
|
126
157
|
def text_xml
|
@@ -146,7 +177,7 @@ module Mime
|
|
146
177
|
end
|
147
178
|
|
148
179
|
def lookup(string)
|
149
|
-
LOOKUP[string]
|
180
|
+
LOOKUP[string]
|
150
181
|
end
|
151
182
|
|
152
183
|
def lookup_by_extension(extension)
|
@@ -160,17 +191,17 @@ module Mime
|
|
160
191
|
end
|
161
192
|
|
162
193
|
def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false)
|
163
|
-
|
194
|
+
new_mime = Type.new(string, symbol, mime_type_synonyms)
|
164
195
|
|
165
|
-
new_mime = Mime.const_get(symbol.upcase)
|
166
196
|
SET << new_mime
|
167
197
|
|
168
|
-
([string] + mime_type_synonyms).each { |str| LOOKUP[str] =
|
169
|
-
([symbol] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext.to_s] =
|
198
|
+
([string] + mime_type_synonyms).each { |str| LOOKUP[str] = new_mime } unless skip_lookup
|
199
|
+
([symbol] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext.to_s] = new_mime }
|
170
200
|
|
171
201
|
@register_callbacks.each do |callback|
|
172
202
|
callback.call(new_mime)
|
173
203
|
end
|
204
|
+
new_mime
|
174
205
|
end
|
175
206
|
|
176
207
|
def parse(accept_header)
|
@@ -200,37 +231,33 @@ module Mime
|
|
200
231
|
parse_data_with_trailing_star($1) if accept_header =~ TRAILING_STAR_REGEXP
|
201
232
|
end
|
202
233
|
|
203
|
-
# For an input of <tt>'text'</tt>, returns <tt>[Mime
|
204
|
-
# Mime
|
234
|
+
# For an input of <tt>'text'</tt>, returns <tt>[Mime[:json], Mime[:xml], Mime[:ics],
|
235
|
+
# Mime[:html], Mime[:css], Mime[:csv], Mime[:js], Mime[:yaml], Mime[:text]</tt>.
|
205
236
|
#
|
206
|
-
# For an input of <tt>'application'</tt>, returns <tt>[Mime
|
207
|
-
# Mime
|
208
|
-
def parse_data_with_trailing_star(
|
209
|
-
Mime::SET.select { |m| m =~
|
237
|
+
# For an input of <tt>'application'</tt>, returns <tt>[Mime[:html], Mime[:js],
|
238
|
+
# Mime[:xml], Mime[:yaml], Mime[:atom], Mime[:json], Mime[:rss], Mime[:url_encoded_form]</tt>.
|
239
|
+
def parse_data_with_trailing_star(type)
|
240
|
+
Mime::SET.select { |m| m =~ type }
|
210
241
|
end
|
211
242
|
|
212
243
|
# This method is opposite of register method.
|
213
244
|
#
|
214
|
-
#
|
245
|
+
# To unregister a MIME type:
|
215
246
|
#
|
216
247
|
# Mime::Type.unregister(:mobile)
|
217
248
|
def unregister(symbol)
|
218
|
-
symbol = symbol.
|
219
|
-
mime = Mime
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
EXTENSION_LOOKUP.delete_if { |_,v| v.eql?(mime) }
|
249
|
+
symbol = symbol.downcase
|
250
|
+
if mime = Mime[symbol]
|
251
|
+
SET.delete_if { |v| v.eql?(mime) }
|
252
|
+
LOOKUP.delete_if { |_, v| v.eql?(mime) }
|
253
|
+
EXTENSION_LOOKUP.delete_if { |_, v| v.eql?(mime) }
|
254
|
+
end
|
225
255
|
end
|
226
256
|
end
|
227
257
|
|
228
|
-
attr_reader :hash
|
229
|
-
|
230
258
|
def initialize(string, symbol = nil, synonyms = [])
|
231
259
|
@symbol, @synonyms = symbol, synonyms
|
232
260
|
@string = string
|
233
|
-
@hash = [@string, @synonyms, @symbol].hash
|
234
261
|
end
|
235
262
|
|
236
263
|
def to_s
|
@@ -246,7 +273,7 @@ module Mime
|
|
246
273
|
end
|
247
274
|
|
248
275
|
def ref
|
249
|
-
|
276
|
+
symbol || to_s
|
250
277
|
end
|
251
278
|
|
252
279
|
def ===(list)
|
@@ -258,35 +285,23 @@ module Mime
|
|
258
285
|
end
|
259
286
|
|
260
287
|
def ==(mime_type)
|
261
|
-
return false
|
288
|
+
return false unless mime_type
|
262
289
|
(@synonyms + [ self ]).any? do |synonym|
|
263
290
|
synonym.to_s == mime_type.to_s || synonym.to_sym == mime_type.to_sym
|
264
291
|
end
|
265
292
|
end
|
266
293
|
|
267
|
-
def eql?(other)
|
268
|
-
super || (self.class == other.class &&
|
269
|
-
@string == other.string &&
|
270
|
-
@synonyms == other.synonyms &&
|
271
|
-
@symbol == other.symbol)
|
272
|
-
end
|
273
|
-
|
274
294
|
def =~(mime_type)
|
275
|
-
return false
|
295
|
+
return false unless mime_type
|
276
296
|
regexp = Regexp.new(Regexp.quote(mime_type.to_s))
|
277
|
-
|
278
|
-
synonym.to_s =~ regexp
|
279
|
-
end
|
297
|
+
@synonyms.any? { |synonym| synonym.to_s =~ regexp } || @string =~ regexp
|
280
298
|
end
|
281
299
|
|
282
300
|
def html?
|
283
|
-
|
301
|
+
symbol == :html || @string =~ /html/
|
284
302
|
end
|
285
303
|
|
286
|
-
|
287
|
-
protected
|
288
|
-
|
289
|
-
attr_reader :string, :synonyms
|
304
|
+
def all?; false; end
|
290
305
|
|
291
306
|
private
|
292
307
|
|
@@ -306,6 +321,22 @@ module Mime
|
|
306
321
|
end
|
307
322
|
end
|
308
323
|
|
324
|
+
class AllType < Type
|
325
|
+
include Singleton
|
326
|
+
|
327
|
+
def initialize
|
328
|
+
super '*/*', :all
|
329
|
+
end
|
330
|
+
|
331
|
+
def all?; true; end
|
332
|
+
def html?; true; end
|
333
|
+
end
|
334
|
+
|
335
|
+
# ALL isn't a real MIME type, so we don't register it for lookup with the
|
336
|
+
# other concrete types. It's a wildcard match that we use for `respond_to`
|
337
|
+
# negotiation internals.
|
338
|
+
ALL = AllType.instance
|
339
|
+
|
309
340
|
class NullType
|
310
341
|
include Singleton
|
311
342
|
|
@@ -27,10 +27,7 @@ Mime::Type.register "application/x-www-form-urlencoded", :url_encoded_form
|
|
27
27
|
|
28
28
|
# http://www.ietf.org/rfc/rfc4627.txt
|
29
29
|
# http://www.json.org/JSONRequest.html
|
30
|
-
Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest )
|
30
|
+
Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest application/vnd.api+json )
|
31
31
|
|
32
32
|
Mime::Type.register "application/pdf", :pdf, [], %w(pdf)
|
33
33
|
Mime::Type.register "application/zip", :zip, [], %w(zip)
|
34
|
-
|
35
|
-
# Create Mime::ALL but do not add it to the SET.
|
36
|
-
Mime::ALL = Mime::Type.new("*/*", :all, [])
|
@@ -30,36 +30,46 @@ module ActionDispatch
|
|
30
30
|
when Regexp
|
31
31
|
regexps << item
|
32
32
|
else
|
33
|
-
strings << item.to_s
|
33
|
+
strings << Regexp.escape(item.to_s)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
regexps
|
38
|
-
|
37
|
+
deep_regexps, regexps = regexps.partition { |r| r.to_s.include?("\\.".freeze) }
|
38
|
+
deep_strings, strings = strings.partition { |s| s.include?("\\.".freeze) }
|
39
|
+
|
40
|
+
regexps << Regexp.new(strings.join('|'.freeze), true) unless strings.empty?
|
41
|
+
deep_regexps << Regexp.new(deep_strings.join('|'.freeze), true) unless deep_strings.empty?
|
42
|
+
|
43
|
+
new regexps, deep_regexps, blocks
|
39
44
|
end
|
40
45
|
|
41
|
-
attr_reader :regexps, :blocks
|
46
|
+
attr_reader :regexps, :deep_regexps, :blocks
|
42
47
|
|
43
|
-
def initialize(regexps, blocks)
|
48
|
+
def initialize(regexps, deep_regexps, blocks)
|
44
49
|
@regexps = regexps
|
50
|
+
@deep_regexps = deep_regexps.any? ? deep_regexps : nil
|
45
51
|
@blocks = blocks
|
46
52
|
end
|
47
53
|
|
48
|
-
def call(original_params)
|
54
|
+
def call(original_params, parents = [])
|
49
55
|
filtered_params = {}
|
50
56
|
|
51
57
|
original_params.each do |key, value|
|
58
|
+
parents.push(key) if deep_regexps
|
52
59
|
if regexps.any? { |r| key =~ r }
|
53
60
|
value = FILTERED
|
61
|
+
elsif deep_regexps && (joined = parents.join('.')) && deep_regexps.any? { |r| joined =~ r }
|
62
|
+
value = FILTERED
|
54
63
|
elsif value.is_a?(Hash)
|
55
|
-
value = call(value)
|
64
|
+
value = call(value, parents)
|
56
65
|
elsif value.is_a?(Array)
|
57
|
-
value = value.map { |v| v.is_a?(Hash) ? call(v) : v }
|
66
|
+
value = value.map { |v| v.is_a?(Hash) ? call(v, parents) : v }
|
58
67
|
elsif blocks.any?
|
59
68
|
key = key.dup if key.duplicable?
|
60
69
|
value = value.dup if value.duplicable?
|
61
70
|
blocks.each { |b| b.call(key, value) }
|
62
71
|
end
|
72
|
+
parents.pop if deep_regexps
|
63
73
|
|
64
74
|
filtered_params[key] = value
|
65
75
|
end
|
@@ -1,35 +1,41 @@
|
|
1
|
-
require 'active_support/core_ext/hash/keys'
|
2
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
-
require 'active_support/deprecation'
|
4
|
-
|
5
1
|
module ActionDispatch
|
6
2
|
module Http
|
7
3
|
module Parameters
|
8
4
|
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
|
9
5
|
|
6
|
+
DEFAULT_PARSERS = {
|
7
|
+
Mime[:json] => lambda { |raw_post|
|
8
|
+
data = ActiveSupport::JSON.decode(raw_post)
|
9
|
+
data.is_a?(Hash) ? data : {:_json => data}
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
def self.included(klass)
|
14
|
+
class << klass
|
15
|
+
attr_accessor :parameter_parsers
|
16
|
+
end
|
17
|
+
|
18
|
+
klass.parameter_parsers = DEFAULT_PARSERS
|
19
|
+
end
|
10
20
|
# Returns both GET and POST \parameters in a single hash.
|
11
21
|
def parameters
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
params = get_header("action_dispatch.request.parameters")
|
23
|
+
return params if params
|
24
|
+
|
25
|
+
params = begin
|
26
|
+
request_parameters.merge(query_parameters)
|
27
|
+
rescue EOFError
|
28
|
+
query_parameters.dup
|
29
|
+
end
|
30
|
+
params.merge!(path_parameters)
|
31
|
+
set_header("action_dispatch.request.parameters", params)
|
32
|
+
params
|
20
33
|
end
|
21
34
|
alias :params :parameters
|
22
35
|
|
23
36
|
def path_parameters=(parameters) #:nodoc:
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def symbolized_path_parameters
|
29
|
-
ActiveSupport::Deprecation.warn(
|
30
|
-
'`symbolized_path_parameters` is deprecated. Please use `path_parameters`.'
|
31
|
-
)
|
32
|
-
path_parameters
|
37
|
+
delete_header('action_dispatch.request.parameters')
|
38
|
+
set_header PARAMETERS_KEY, parameters
|
33
39
|
end
|
34
40
|
|
35
41
|
# Returns a hash with the \parameters used to form the \path of the request.
|
@@ -37,31 +43,29 @@ module ActionDispatch
|
|
37
43
|
#
|
38
44
|
# {'action' => 'my_action', 'controller' => 'my_controller'}
|
39
45
|
def path_parameters
|
40
|
-
|
46
|
+
get_header(PARAMETERS_KEY) || {}
|
41
47
|
end
|
42
48
|
|
43
|
-
|
49
|
+
private
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
normalize_encode_params(val)
|
58
|
-
end
|
59
|
-
end.with_indifferent_access
|
60
|
-
end
|
61
|
-
else
|
62
|
-
params
|
51
|
+
def parse_formatted_parameters(parsers)
|
52
|
+
return yield if content_length.zero?
|
53
|
+
|
54
|
+
strategy = parsers.fetch(content_mime_type) { return yield }
|
55
|
+
|
56
|
+
begin
|
57
|
+
strategy.call(raw_post)
|
58
|
+
rescue # JSON or Ruby code block errors
|
59
|
+
my_logger = logger || ActiveSupport::Logger.new($stderr)
|
60
|
+
my_logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{raw_post}"
|
61
|
+
|
62
|
+
raise ParamsParser::ParseError
|
63
63
|
end
|
64
64
|
end
|
65
|
+
|
66
|
+
def params_parsers
|
67
|
+
ActionDispatch::Request.parameter_parsers
|
68
|
+
end
|
65
69
|
end
|
66
70
|
end
|
67
71
|
end
|