actionpack 4.0.13 → 4.1.0.beta1

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.
Files changed (194) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +131 -1636
  3. data/README.rdoc +1 -6
  4. data/lib/abstract_controller.rb +1 -2
  5. data/lib/abstract_controller/base.rb +3 -25
  6. data/lib/abstract_controller/callbacks.rb +4 -2
  7. data/lib/abstract_controller/collector.rb +11 -1
  8. data/lib/abstract_controller/helpers.rb +18 -15
  9. data/lib/abstract_controller/rendering.rb +48 -127
  10. data/lib/action_controller.rb +1 -17
  11. data/lib/action_controller/base.rb +14 -6
  12. data/lib/action_controller/caching.rb +1 -11
  13. data/lib/action_controller/log_subscriber.rb +1 -1
  14. data/lib/action_controller/metal.rb +0 -4
  15. data/lib/action_controller/metal/flash.rb +17 -0
  16. data/lib/action_controller/metal/force_ssl.rb +1 -1
  17. data/lib/action_controller/metal/head.rb +1 -3
  18. data/lib/action_controller/metal/helpers.rb +6 -2
  19. data/lib/action_controller/metal/http_authentication.rb +7 -14
  20. data/lib/action_controller/metal/instrumentation.rb +1 -1
  21. data/lib/action_controller/metal/live.rb +74 -0
  22. data/lib/action_controller/metal/mime_responds.rb +93 -16
  23. data/lib/action_controller/metal/params_wrapper.rb +4 -11
  24. data/lib/action_controller/metal/rack_delegation.rb +1 -1
  25. data/lib/action_controller/metal/redirecting.rb +20 -20
  26. data/lib/action_controller/metal/renderers.rb +8 -5
  27. data/lib/action_controller/metal/rendering.rb +14 -11
  28. data/lib/action_controller/metal/request_forgery_protection.rb +67 -13
  29. data/lib/action_controller/metal/responder.rb +12 -2
  30. data/lib/action_controller/metal/streaming.rb +18 -20
  31. data/lib/action_controller/metal/strong_parameters.rb +22 -34
  32. data/lib/action_controller/railtie.rb +0 -1
  33. data/lib/action_controller/test_case.rb +0 -15
  34. data/lib/action_dispatch.rb +1 -0
  35. data/lib/action_dispatch/http/headers.rb +1 -3
  36. data/lib/action_dispatch/http/mime_negotiation.rb +16 -2
  37. data/lib/action_dispatch/http/mime_type.rb +4 -22
  38. data/lib/action_dispatch/http/mime_types.rb +1 -0
  39. data/lib/action_dispatch/http/parameters.rb +18 -19
  40. data/lib/action_dispatch/http/request.rb +16 -25
  41. data/lib/action_dispatch/http/response.rb +21 -8
  42. data/lib/action_dispatch/http/upload.rb +0 -13
  43. data/lib/action_dispatch/http/url.rb +10 -18
  44. data/lib/action_dispatch/journey/formatter.rb +3 -3
  45. data/lib/action_dispatch/journey/gtg/transition_table.rb +3 -5
  46. data/lib/action_dispatch/journey/parser.rb +1 -1
  47. data/lib/action_dispatch/journey/parser.y +1 -0
  48. data/lib/action_dispatch/journey/router.rb +7 -1
  49. data/lib/action_dispatch/journey/router/utils.rb +1 -1
  50. data/lib/action_dispatch/journey/visitors.rb +26 -47
  51. data/lib/action_dispatch/middleware/callbacks.rb +6 -6
  52. data/lib/action_dispatch/middleware/cookies.rb +15 -15
  53. data/lib/action_dispatch/middleware/debug_exceptions.rb +21 -13
  54. data/lib/action_dispatch/middleware/exception_wrapper.rb +1 -1
  55. data/lib/action_dispatch/middleware/flash.rb +5 -11
  56. data/lib/action_dispatch/middleware/params_parser.rb +1 -1
  57. data/lib/action_dispatch/middleware/public_exceptions.rb +1 -5
  58. data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
  59. data/lib/action_dispatch/middleware/session/cookie_store.rb +4 -3
  60. data/lib/action_dispatch/middleware/show_exceptions.rb +5 -2
  61. data/lib/action_dispatch/middleware/ssl.rb +1 -1
  62. data/lib/action_dispatch/middleware/static.rb +5 -25
  63. data/lib/action_dispatch/middleware/templates/rescues/{_request_and_response.erb → _request_and_response.html.erb} +0 -0
  64. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  65. data/lib/action_dispatch/middleware/templates/rescues/{_trace.erb → _trace.html.erb} +0 -0
  66. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +15 -0
  67. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +1 -1
  68. data/lib/action_dispatch/middleware/templates/rescues/{missing_template.erb → missing_template.html.erb} +1 -1
  69. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  70. data/lib/action_dispatch/middleware/templates/rescues/{routing_error.erb → routing_error.html.erb} +1 -1
  71. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  72. data/lib/action_dispatch/middleware/templates/rescues/{template_error.erb → template_error.html.erb} +1 -1
  73. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +8 -0
  74. data/lib/action_dispatch/middleware/templates/rescues/{unknown_action.erb → unknown_action.html.erb} +1 -1
  75. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  76. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +3 -3
  77. data/lib/action_dispatch/railtie.rb +1 -2
  78. data/lib/action_dispatch/request/session.rb +12 -0
  79. data/lib/action_dispatch/request/utils.rb +24 -0
  80. data/lib/action_dispatch/routing.rb +7 -6
  81. data/lib/action_dispatch/routing/inspector.rb +4 -4
  82. data/lib/action_dispatch/routing/mapper.rb +81 -138
  83. data/lib/action_dispatch/routing/polymorphic_routes.rb +13 -0
  84. data/lib/action_dispatch/routing/redirection.rb +34 -27
  85. data/lib/action_dispatch/routing/route_set.rb +43 -37
  86. data/lib/action_dispatch/routing/url_for.rb +3 -1
  87. data/lib/action_dispatch/testing/assertions/response.rb +8 -15
  88. data/lib/action_dispatch/testing/assertions/selector.rb +4 -4
  89. data/lib/action_dispatch/testing/integration.rb +1 -7
  90. data/lib/action_pack/version.rb +1 -1
  91. metadata +43 -167
  92. data/lib/abstract_controller/layouts.rb +0 -423
  93. data/lib/abstract_controller/view_paths.rb +0 -96
  94. data/lib/action_controller/deprecated.rb +0 -7
  95. data/lib/action_controller/deprecated/integration_test.rb +0 -5
  96. data/lib/action_controller/record_identifier.rb +0 -31
  97. data/lib/action_controller/vendor/html-scanner.rb +0 -5
  98. data/lib/action_view.rb +0 -93
  99. data/lib/action_view/base.rb +0 -205
  100. data/lib/action_view/buffers.rb +0 -49
  101. data/lib/action_view/context.rb +0 -36
  102. data/lib/action_view/dependency_tracker.rb +0 -93
  103. data/lib/action_view/digestor.rb +0 -113
  104. data/lib/action_view/flows.rb +0 -76
  105. data/lib/action_view/helpers.rb +0 -58
  106. data/lib/action_view/helpers/active_model_helper.rb +0 -49
  107. data/lib/action_view/helpers/asset_tag_helper.rb +0 -320
  108. data/lib/action_view/helpers/asset_url_helper.rb +0 -355
  109. data/lib/action_view/helpers/atom_feed_helper.rb +0 -203
  110. data/lib/action_view/helpers/cache_helper.rb +0 -196
  111. data/lib/action_view/helpers/capture_helper.rb +0 -216
  112. data/lib/action_view/helpers/controller_helper.rb +0 -25
  113. data/lib/action_view/helpers/csrf_helper.rb +0 -32
  114. data/lib/action_view/helpers/date_helper.rb +0 -1087
  115. data/lib/action_view/helpers/debug_helper.rb +0 -39
  116. data/lib/action_view/helpers/form_helper.rb +0 -1882
  117. data/lib/action_view/helpers/form_options_helper.rb +0 -838
  118. data/lib/action_view/helpers/form_tag_helper.rb +0 -785
  119. data/lib/action_view/helpers/javascript_helper.rb +0 -117
  120. data/lib/action_view/helpers/number_helper.rb +0 -451
  121. data/lib/action_view/helpers/output_safety_helper.rb +0 -38
  122. data/lib/action_view/helpers/record_tag_helper.rb +0 -106
  123. data/lib/action_view/helpers/rendering_helper.rb +0 -90
  124. data/lib/action_view/helpers/sanitize_helper.rb +0 -256
  125. data/lib/action_view/helpers/tag_helper.rb +0 -173
  126. data/lib/action_view/helpers/tags.rb +0 -39
  127. data/lib/action_view/helpers/tags/base.rb +0 -148
  128. data/lib/action_view/helpers/tags/check_box.rb +0 -64
  129. data/lib/action_view/helpers/tags/checkable.rb +0 -16
  130. data/lib/action_view/helpers/tags/collection_check_boxes.rb +0 -53
  131. data/lib/action_view/helpers/tags/collection_helpers.rb +0 -84
  132. data/lib/action_view/helpers/tags/collection_radio_buttons.rb +0 -36
  133. data/lib/action_view/helpers/tags/collection_select.rb +0 -28
  134. data/lib/action_view/helpers/tags/color_field.rb +0 -25
  135. data/lib/action_view/helpers/tags/date_field.rb +0 -13
  136. data/lib/action_view/helpers/tags/date_select.rb +0 -72
  137. data/lib/action_view/helpers/tags/datetime_field.rb +0 -22
  138. data/lib/action_view/helpers/tags/datetime_local_field.rb +0 -19
  139. data/lib/action_view/helpers/tags/datetime_select.rb +0 -8
  140. data/lib/action_view/helpers/tags/email_field.rb +0 -8
  141. data/lib/action_view/helpers/tags/file_field.rb +0 -8
  142. data/lib/action_view/helpers/tags/grouped_collection_select.rb +0 -29
  143. data/lib/action_view/helpers/tags/hidden_field.rb +0 -8
  144. data/lib/action_view/helpers/tags/label.rb +0 -65
  145. data/lib/action_view/helpers/tags/month_field.rb +0 -13
  146. data/lib/action_view/helpers/tags/number_field.rb +0 -18
  147. data/lib/action_view/helpers/tags/password_field.rb +0 -12
  148. data/lib/action_view/helpers/tags/radio_button.rb +0 -31
  149. data/lib/action_view/helpers/tags/range_field.rb +0 -8
  150. data/lib/action_view/helpers/tags/search_field.rb +0 -22
  151. data/lib/action_view/helpers/tags/select.rb +0 -40
  152. data/lib/action_view/helpers/tags/tel_field.rb +0 -8
  153. data/lib/action_view/helpers/tags/text_area.rb +0 -18
  154. data/lib/action_view/helpers/tags/text_field.rb +0 -30
  155. data/lib/action_view/helpers/tags/time_field.rb +0 -13
  156. data/lib/action_view/helpers/tags/time_select.rb +0 -8
  157. data/lib/action_view/helpers/tags/time_zone_select.rb +0 -20
  158. data/lib/action_view/helpers/tags/url_field.rb +0 -8
  159. data/lib/action_view/helpers/tags/week_field.rb +0 -13
  160. data/lib/action_view/helpers/text_helper.rb +0 -448
  161. data/lib/action_view/helpers/translation_helper.rb +0 -112
  162. data/lib/action_view/helpers/url_helper.rb +0 -635
  163. data/lib/action_view/locale/en.yml +0 -56
  164. data/lib/action_view/log_subscriber.rb +0 -30
  165. data/lib/action_view/lookup_context.rb +0 -248
  166. data/lib/action_view/model_naming.rb +0 -12
  167. data/lib/action_view/path_set.rb +0 -77
  168. data/lib/action_view/railtie.rb +0 -43
  169. data/lib/action_view/record_identifier.rb +0 -84
  170. data/lib/action_view/renderer/abstract_renderer.rb +0 -47
  171. data/lib/action_view/renderer/partial_renderer.rb +0 -500
  172. data/lib/action_view/renderer/renderer.rb +0 -50
  173. data/lib/action_view/renderer/streaming_template_renderer.rb +0 -103
  174. data/lib/action_view/renderer/template_renderer.rb +0 -96
  175. data/lib/action_view/routing_url_for.rb +0 -107
  176. data/lib/action_view/tasks/dependencies.rake +0 -17
  177. data/lib/action_view/template.rb +0 -339
  178. data/lib/action_view/template/error.rb +0 -138
  179. data/lib/action_view/template/handlers.rb +0 -53
  180. data/lib/action_view/template/handlers/builder.rb +0 -26
  181. data/lib/action_view/template/handlers/erb.rb +0 -146
  182. data/lib/action_view/template/handlers/raw.rb +0 -11
  183. data/lib/action_view/template/resolver.rb +0 -340
  184. data/lib/action_view/template/text.rb +0 -34
  185. data/lib/action_view/template/types.rb +0 -57
  186. data/lib/action_view/test_case.rb +0 -270
  187. data/lib/action_view/testing/resolvers.rb +0 -50
  188. data/lib/action_view/vendor/html-scanner.rb +0 -20
  189. data/lib/action_view/vendor/html-scanner/html/document.rb +0 -68
  190. data/lib/action_view/vendor/html-scanner/html/node.rb +0 -532
  191. data/lib/action_view/vendor/html-scanner/html/sanitizer.rb +0 -188
  192. data/lib/action_view/vendor/html-scanner/html/selector.rb +0 -830
  193. data/lib/action_view/vendor/html-scanner/html/tokenizer.rb +0 -107
  194. data/lib/action_view/vendor/html-scanner/html/version.rb +0 -11
@@ -1,7 +1,6 @@
1
1
  require "rails"
2
2
  require "action_controller"
3
3
  require "action_dispatch/railtie"
4
- require "action_view/railtie"
5
4
  require "abstract_controller/railties/routes_helpers"
6
5
  require "action_controller/railties/helpers"
7
6
 
@@ -213,9 +213,6 @@ module ActionController
213
213
  # Clear the combined params hash in case it was already referenced.
214
214
  @env.delete("action_dispatch.request.parameters")
215
215
 
216
- # Clear the filter cache variables so they're not stale
217
- @filtered_parameters = @filtered_env = @filtered_path = nil
218
-
219
216
  params = self.request_parameters.dup
220
217
  %w(controller action only_path).each do |k|
221
218
  params.delete(k)
@@ -527,7 +524,6 @@ module ActionController
527
524
 
528
525
  def process(action, http_method = 'GET', *args)
529
526
  check_required_ivars
530
- http_method, args = handle_old_process_api(http_method, args, caller)
531
527
 
532
528
  if args.first.is_a?(String) && http_method != 'HEAD'
533
529
  @request.env['RAW_POST_DATA'] = args.shift
@@ -631,17 +627,6 @@ module ActionController
631
627
  end
632
628
  end
633
629
 
634
- def handle_old_process_api(http_method, args, callstack)
635
- # 4.0: Remove this method.
636
- if http_method.is_a?(Hash)
637
- ActiveSupport::Deprecation.warn("TestCase#process now expects the HTTP method as second argument: process(action, http_method, params, session, flash)", callstack)
638
- args.unshift(http_method)
639
- http_method = args.last.is_a?(String) ? args.last : "GET"
640
- end
641
-
642
- [http_method, args]
643
- end
644
-
645
630
  def build_request_uri(action, parameters)
646
631
  unless @request.env["PATH_INFO"]
647
632
  options = @controller.respond_to?(:url_options) ? @controller.__send__(:url_options).merge(parameters) : parameters
@@ -52,6 +52,7 @@ module ActionDispatch
52
52
  autoload :DebugExceptions
53
53
  autoload :ExceptionWrapper
54
54
  autoload :Flash
55
+ autoload :Head
55
56
  autoload :ParamsParser
56
57
  autoload :PublicExceptions
57
58
  autoload :Reloader
@@ -26,9 +26,7 @@ module ActionDispatch
26
26
  @env[env_name(key)] = value
27
27
  end
28
28
 
29
- def key?(key)
30
- @env.key? env_name(key)
31
- end
29
+ def key?(key); @env.key? key; end
32
30
  alias :include? :key?
33
31
 
34
32
  def fetch(key, *args, &block)
@@ -10,6 +10,8 @@ module ActionDispatch
10
10
  self.ignore_accept_header = false
11
11
  end
12
12
 
13
+ attr_reader :variant
14
+
13
15
  # The MIME type of the HTTP request, such as Mime::XML.
14
16
  #
15
17
  # For backward compatibility, the post \format is extracted from the
@@ -48,7 +50,7 @@ module ActionDispatch
48
50
  # GET /posts/5 | request.format => Mime::HTML or MIME::JS, or request.accepts.first
49
51
  #
50
52
  def format(view_path = [])
51
- formats.first || Mime::NullType.instance
53
+ formats.first
52
54
  end
53
55
 
54
56
  def formats
@@ -64,6 +66,18 @@ module ActionDispatch
64
66
  end
65
67
  end
66
68
 
69
+ # Sets the \variant for template.
70
+ def variant=(variant)
71
+ if variant.is_a? Symbol
72
+ @variant = variant
73
+ else
74
+ raise ArgumentError, "request.variant must be set to a Symbol, not a #{variant.class}. " \
75
+ "For security reasons, never directly set the variant to a user-provided value, " \
76
+ "like params[:variant].to_sym. Check user-provided value against a whitelist first, " \
77
+ "then set the variant: request.variant = :tablet if params[:variant] == 'tablet'"
78
+ end
79
+ end
80
+
67
81
  # Sets the \format by string extension, which can be used to force custom formats
68
82
  # that are not controlled by the extension.
69
83
  #
@@ -113,7 +127,7 @@ module ActionDispatch
113
127
  end
114
128
  end
115
129
 
116
- order.include?(Mime::ALL) ? format : nil
130
+ order.include?(Mime::ALL) ? formats.first : nil
117
131
  end
118
132
 
119
133
  protected
@@ -1,6 +1,6 @@
1
1
  require 'set'
2
2
  require 'singleton'
3
- require 'active_support/core_ext/class/attribute_accessors'
3
+ require 'active_support/core_ext/module/attribute_accessors'
4
4
  require 'active_support/core_ext/string/starts_ends_with'
5
5
 
6
6
  module Mime
@@ -28,7 +28,7 @@ module Mime
28
28
  class << self
29
29
  def [](type)
30
30
  return type if type.is_a?(Type)
31
- Type.lookup_by_extension(type)
31
+ Type.lookup_by_extension(type) || NullType.instance
32
32
  end
33
33
 
34
34
  def fetch(type)
@@ -54,10 +54,6 @@ module Mime
54
54
  @@html_types = Set.new [:html, :all]
55
55
  cattr_reader :html_types
56
56
 
57
- # These are the content types which browsers can generate without using ajax, flash, etc
58
- # i.e. following a link, getting an image or posting a form. CSRF protection
59
- # only needs to protect against these types.
60
- @@browser_generated_types = Set.new [:html, :url_encoded_form, :multipart_form, :text]
61
57
  attr_reader :symbol
62
58
 
63
59
  @register_callbacks = []
@@ -178,7 +174,7 @@ module Mime
178
174
  end
179
175
 
180
176
  def parse(accept_header)
181
- if !accept_header.include?(',')
177
+ if accept_header !~ /,/
182
178
  accept_header = accept_header.split(PARAMETER_SEPARATOR_REGEXP).first
183
179
  parse_trailing_star(accept_header) || [Mime::Type.lookup(accept_header)].compact
184
180
  else
@@ -273,18 +269,6 @@ module Mime
273
269
  end
274
270
  end
275
271
 
276
- # Returns true if Action Pack should check requests using this Mime Type for possible request forgery. See
277
- # ActionController::RequestForgeryProtection.
278
- def verify_request?
279
- ActiveSupport::Deprecation.warn "Mime::Type#verify_request? is deprecated and will be removed in Rails 4.1"
280
- @@browser_generated_types.include?(to_sym)
281
- end
282
-
283
- def self.browser_generated_types
284
- ActiveSupport::Deprecation.warn "Mime::Type.browser_generated_types is deprecated and will be removed in Rails 4.1"
285
- @@browser_generated_types
286
- end
287
-
288
272
  def html?
289
273
  @@html_types.include?(to_sym) || @string =~ /html/
290
274
  end
@@ -315,9 +299,7 @@ module Mime
315
299
  true
316
300
  end
317
301
 
318
- def ref
319
- nil
320
- end
302
+ def ref; end
321
303
 
322
304
  def respond_to_missing?(method, include_private = false)
323
305
  method.to_s.ends_with? '?'
@@ -7,6 +7,7 @@ Mime::Type.register "text/javascript", :js, %w( application/javascript applicati
7
7
  Mime::Type.register "text/css", :css
8
8
  Mime::Type.register "text/calendar", :ics
9
9
  Mime::Type.register "text/csv", :csv
10
+ Mime::Type.register "text/vcard", :vcf
10
11
 
11
12
  Mime::Type.register "image/png", :png, [], %w(png)
12
13
  Mime::Type.register "image/jpeg", :jpeg, [], %w(jpg jpeg jpe pjpeg)
@@ -57,26 +57,25 @@ module ActionDispatch
57
57
  # you'll get a weird error down the road, but our form handling
58
58
  # should really prevent that from happening
59
59
  def normalize_encode_params(params)
60
- if params.is_a?(String)
61
- return params.force_encoding(Encoding::UTF_8).encode!
62
- elsif !params.is_a?(Hash)
63
- return params
64
- end
65
-
66
- new_hash = {}
67
- params.each do |k, v|
68
- new_key = k.is_a?(String) ? k.dup.force_encoding(Encoding::UTF_8).encode! : k
69
- new_hash[new_key] =
70
- case v
71
- when Hash
72
- normalize_encode_params(v)
73
- when Array
74
- v.map! {|el| normalize_encode_params(el) }
75
- else
76
- normalize_encode_params(v)
77
- end
60
+ case params
61
+ when String
62
+ params.force_encoding(Encoding::UTF_8).encode!
63
+ when Hash
64
+ if params.has_key?(:tempfile)
65
+ UploadedFile.new(params)
66
+ else
67
+ params.each_with_object({}) do |(key, val), new_hash|
68
+ new_key = key.is_a?(String) ? key.dup.force_encoding(Encoding::UTF_8).encode! : key
69
+ new_hash[new_key] = if val.is_a?(Array)
70
+ val.map! { |el| normalize_encode_params(el) }
71
+ else
72
+ normalize_encode_params(val)
73
+ end
74
+ end.with_indifferent_access
75
+ end
76
+ else
77
+ params
78
78
  end
79
- new_hash.with_indifferent_access
80
79
  end
81
80
  end
82
81
  end
@@ -18,10 +18,10 @@ module ActionDispatch
18
18
  include ActionDispatch::Http::MimeNegotiation
19
19
  include ActionDispatch::Http::Parameters
20
20
  include ActionDispatch::Http::FilterParameters
21
- include ActionDispatch::Http::Upload
22
21
  include ActionDispatch::Http::URL
23
22
 
24
23
  autoload :Session, 'action_dispatch/request/session'
24
+ autoload :Utils, 'action_dispatch/request/utils'
25
25
 
26
26
  LOCALHOST = Regexp.union [/^127\.0\.0\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/]
27
27
 
@@ -225,7 +225,7 @@ module ActionDispatch
225
225
  def raw_post
226
226
  unless @env.include? 'RAW_POST_DATA'
227
227
  raw_post_body = body
228
- @env['RAW_POST_DATA'] = raw_post_body.read(@env['CONTENT_LENGTH'].to_i)
228
+ @env['RAW_POST_DATA'] = raw_post_body.read(content_length)
229
229
  raw_post_body.rewind if raw_post_body.respond_to?(:rewind)
230
230
  end
231
231
  @env['RAW_POST_DATA']
@@ -271,7 +271,7 @@ module ActionDispatch
271
271
 
272
272
  # Override Rack's GET method to support indifferent access
273
273
  def GET
274
- @env["action_dispatch.request.query_parameters"] ||= deep_munge((normalize_encode_params(super) || {}))
274
+ @env["action_dispatch.request.query_parameters"] ||= Utils.deep_munge((normalize_encode_params(super) || {}))
275
275
  rescue TypeError => e
276
276
  raise ActionController::BadRequest.new(:query, e)
277
277
  end
@@ -279,7 +279,7 @@ module ActionDispatch
279
279
 
280
280
  # Override Rack's POST method to support indifferent access
281
281
  def POST
282
- @env["action_dispatch.request.request_parameters"] ||= deep_munge((normalize_encode_params(super) || {}))
282
+ @env["action_dispatch.request.request_parameters"] ||= Utils.deep_munge((normalize_encode_params(super) || {}))
283
283
  rescue TypeError => e
284
284
  raise ActionController::BadRequest.new(:request, e)
285
285
  end
@@ -299,33 +299,24 @@ module ActionDispatch
299
299
  LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip
300
300
  end
301
301
 
302
- # Remove nils from the params hash
302
+ # Extracted into ActionDispatch::Request::Utils.deep_munge, but kept here for backwards compatibility.
303
303
  def deep_munge(hash)
304
- hash.each do |k, v|
305
- case v
306
- when Array
307
- v.grep(Hash) { |x| deep_munge(x) }
308
- v.compact!
309
- hash[k] = nil if v.empty?
310
- when Hash
311
- deep_munge(v)
312
- end
313
- end
304
+ ActiveSupport::Deprecation.warn(
305
+ "This method has been extracted into ActionDispatch::Request::Utils.deep_munge. Please start using that instead."
306
+ )
314
307
 
315
- hash
308
+ Utils.deep_munge(hash)
316
309
  end
317
310
 
318
311
  protected
319
-
320
- def parse_query(qs)
321
- deep_munge(super)
322
- end
312
+ def parse_query(qs)
313
+ Utils.deep_munge(super)
314
+ end
323
315
 
324
316
  private
325
-
326
- def check_method(name)
327
- HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS[0...-1].join(', ')}, and #{HTTP_METHODS[-1]}")
328
- name
329
- end
317
+ def check_method(name)
318
+ HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
319
+ name
320
+ end
330
321
  end
331
322
  end
@@ -1,4 +1,4 @@
1
- require 'active_support/core_ext/class/attribute_accessors'
1
+ require 'active_support/core_ext/module/attribute_accessors'
2
2
  require 'monitor'
3
3
 
4
4
  module ActionDispatch # :nodoc:
@@ -31,10 +31,17 @@ module ActionDispatch # :nodoc:
31
31
  # end
32
32
  # end
33
33
  class Response
34
- attr_accessor :request, :header
34
+ # The request that the response is responding to.
35
+ attr_accessor :request
36
+
37
+ # The HTTP status code.
35
38
  attr_reader :status
39
+
36
40
  attr_writer :sending_file
37
41
 
42
+ # Get and set headers for this response.
43
+ attr_accessor :header
44
+
38
45
  alias_method :headers=, :header=
39
46
  alias_method :headers, :header
40
47
 
@@ -49,9 +56,12 @@ module ActionDispatch # :nodoc:
49
56
  # If a character set has been defined for this response (see charset=) then
50
57
  # the character set information will also be included in the content type
51
58
  # information.
52
- attr_accessor :charset
53
59
  attr_reader :content_type
54
60
 
61
+ # The charset of the response. HTML wants to know the encoding of the
62
+ # content you're giving them, so we need to send that along.
63
+ attr_accessor :charset
64
+
55
65
  CONTENT_TYPE = "Content-Type".freeze
56
66
  SET_COOKIE = "Set-Cookie".freeze
57
67
  LOCATION = "Location".freeze
@@ -93,6 +103,7 @@ module ActionDispatch # :nodoc:
93
103
  end
94
104
  end
95
105
 
106
+ # The underlying body, as a streamable object.
96
107
  attr_reader :stream
97
108
 
98
109
  def initialize(status = 200, header = {}, body = [])
@@ -142,6 +153,7 @@ module ActionDispatch # :nodoc:
142
153
  @status = Rack::Utils.status_code(status)
143
154
  end
144
155
 
156
+ # Sets the HTTP content type.
145
157
  def content_type=(content_type)
146
158
  @content_type = content_type.to_s
147
159
  end
@@ -171,7 +183,7 @@ module ActionDispatch # :nodoc:
171
183
 
172
184
  def respond_to?(method, include_private = false)
173
185
  if method.to_s == 'to_path'
174
- stream.respond_to?(:to_path)
186
+ stream.respond_to?(method)
175
187
  else
176
188
  super
177
189
  end
@@ -218,11 +230,13 @@ module ActionDispatch # :nodoc:
218
230
  ::Rack::Utils.delete_cookie_header!(header, key, value)
219
231
  end
220
232
 
233
+ # The location header we'll be responding with.
221
234
  def location
222
235
  headers[LOCATION]
223
236
  end
224
237
  alias_method :redirect_url, :location
225
238
 
239
+ # Sets the location header we'll be responding with.
226
240
  def location=(url)
227
241
  headers[LOCATION] = url
228
242
  end
@@ -231,11 +245,13 @@ module ActionDispatch # :nodoc:
231
245
  stream.close if stream.respond_to?(:close)
232
246
  end
233
247
 
248
+ # Turns the Response into a Rack-compatible array of the status, headers,
249
+ # and body.
234
250
  def to_a
235
251
  rack_response @status, @header.to_hash
236
252
  end
237
253
  alias prepare! to_a
238
- alias to_ary to_a # For implicit splat on 1.9.2
254
+ alias to_ary to_a
239
255
 
240
256
  # Returns the response cookies, converted to a Hash of (name => value) pairs
241
257
  #
@@ -254,9 +270,6 @@ module ActionDispatch # :nodoc:
254
270
  cookies
255
271
  end
256
272
 
257
- def _status_code
258
- @status
259
- end
260
273
  private
261
274
 
262
275
  def merge_default_headers(original, default)
@@ -73,18 +73,5 @@ module ActionDispatch
73
73
  filename.force_encoding(Encoding::UTF_8).encode! if filename
74
74
  end
75
75
  end
76
-
77
- module Upload # :nodoc:
78
- # Replace file upload hash with UploadedFile objects
79
- # when normalize and encode parameters.
80
- def normalize_encode_params(value)
81
- if Hash === value && value.has_key?(:tempfile)
82
- UploadedFile.new(value)
83
- else
84
- super
85
- end
86
- end
87
- private :normalize_encode_params
88
- end
89
76
  end
90
77
  end
@@ -34,15 +34,19 @@ module ActionDispatch
34
34
  path = options.delete(:script_name).to_s.chomp("/")
35
35
  path << options.delete(:path).to_s
36
36
 
37
- add_trailing_slash(path) if options[:trailing_slash]
38
-
39
37
  params = options[:params].is_a?(Hash) ? options[:params] : options.slice(:params)
40
38
  params.reject! { |_,v| v.to_param.nil? }
41
39
 
42
40
  result = build_host_url(options)
43
-
44
- result << path
45
-
41
+ if options[:trailing_slash]
42
+ if path.include?('?')
43
+ result << path.sub(/\?/, '/\&')
44
+ else
45
+ result << path.sub(/[^\/]\z|\A\z/, '\&/')
46
+ end
47
+ else
48
+ result << path
49
+ end
46
50
  result << "?#{params.to_query}" unless params.empty?
47
51
  result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor]
48
52
  result
@@ -50,18 +54,6 @@ module ActionDispatch
50
54
 
51
55
  private
52
56
 
53
- def add_trailing_slash(path)
54
- # includes querysting
55
- if path.include?('?')
56
- path.sub!(/\?/, '/\&')
57
- # does not have a .format
58
- elsif !path.include?(".")
59
- path.sub!(/[^\/]\z|\A\z/, '\&/')
60
- end
61
-
62
- path
63
- end
64
-
65
57
  def build_host_url(options)
66
58
  if options[:host].blank? && options[:only_path].blank?
67
59
  raise ArgumentError, 'Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true'
@@ -138,7 +130,7 @@ module ActionDispatch
138
130
 
139
131
  case options[:protocol]
140
132
  when "//"
141
- options[:port]
133
+ nil
142
134
  when "https://"
143
135
  options[:port].to_i == 443 ? nil : options[:port]
144
136
  else