actionpack 7.1.5.1 → 8.1.2

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 (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +308 -523
  3. data/README.rdoc +1 -1
  4. data/lib/abstract_controller/asset_paths.rb +6 -2
  5. data/lib/abstract_controller/base.rb +104 -105
  6. data/lib/abstract_controller/caching/fragments.rb +50 -53
  7. data/lib/abstract_controller/caching.rb +8 -3
  8. data/lib/abstract_controller/callbacks.rb +70 -62
  9. data/lib/abstract_controller/collector.rb +7 -7
  10. data/lib/abstract_controller/deprecator.rb +2 -0
  11. data/lib/abstract_controller/error.rb +2 -0
  12. data/lib/abstract_controller/helpers.rb +71 -84
  13. data/lib/abstract_controller/logger.rb +4 -1
  14. data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
  15. data/lib/abstract_controller/rendering.rb +13 -13
  16. data/lib/abstract_controller/translation.rb +12 -13
  17. data/lib/abstract_controller/url_for.rb +8 -6
  18. data/lib/abstract_controller.rb +2 -0
  19. data/lib/action_controller/api/api_rendering.rb +2 -0
  20. data/lib/action_controller/api.rb +76 -72
  21. data/lib/action_controller/base.rb +199 -126
  22. data/lib/action_controller/caching.rb +16 -14
  23. data/lib/action_controller/deprecator.rb +2 -0
  24. data/lib/action_controller/form_builder.rb +21 -18
  25. data/lib/action_controller/log_subscriber.rb +23 -2
  26. data/lib/action_controller/metal/allow_browser.rb +133 -0
  27. data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
  28. data/lib/action_controller/metal/conditional_get.rb +217 -175
  29. data/lib/action_controller/metal/content_security_policy.rb +25 -24
  30. data/lib/action_controller/metal/cookies.rb +4 -2
  31. data/lib/action_controller/metal/data_streaming.rb +72 -63
  32. data/lib/action_controller/metal/default_headers.rb +5 -3
  33. data/lib/action_controller/metal/etag_with_flash.rb +3 -1
  34. data/lib/action_controller/metal/etag_with_template_digest.rb +17 -15
  35. data/lib/action_controller/metal/exceptions.rb +16 -9
  36. data/lib/action_controller/metal/flash.rb +13 -14
  37. data/lib/action_controller/metal/head.rb +15 -11
  38. data/lib/action_controller/metal/helpers.rb +63 -55
  39. data/lib/action_controller/metal/http_authentication.rb +209 -201
  40. data/lib/action_controller/metal/implicit_render.rb +17 -15
  41. data/lib/action_controller/metal/instrumentation.rb +16 -14
  42. data/lib/action_controller/metal/live.rb +177 -128
  43. data/lib/action_controller/metal/logging.rb +6 -4
  44. data/lib/action_controller/metal/mime_responds.rb +151 -142
  45. data/lib/action_controller/metal/parameter_encoding.rb +34 -32
  46. data/lib/action_controller/metal/params_wrapper.rb +57 -59
  47. data/lib/action_controller/metal/permissions_policy.rb +22 -12
  48. data/lib/action_controller/metal/rate_limiting.rb +92 -0
  49. data/lib/action_controller/metal/redirecting.rb +213 -94
  50. data/lib/action_controller/metal/renderers.rb +78 -57
  51. data/lib/action_controller/metal/rendering.rb +111 -77
  52. data/lib/action_controller/metal/request_forgery_protection.rb +182 -143
  53. data/lib/action_controller/metal/rescue.rb +20 -9
  54. data/lib/action_controller/metal/streaming.rb +118 -195
  55. data/lib/action_controller/metal/strong_parameters.rb +720 -530
  56. data/lib/action_controller/metal/testing.rb +2 -0
  57. data/lib/action_controller/metal/url_for.rb +17 -15
  58. data/lib/action_controller/metal.rb +86 -60
  59. data/lib/action_controller/railtie.rb +36 -15
  60. data/lib/action_controller/railties/helpers.rb +2 -0
  61. data/lib/action_controller/renderer.rb +41 -36
  62. data/lib/action_controller/structured_event_subscriber.rb +116 -0
  63. data/lib/action_controller/template_assertions.rb +4 -2
  64. data/lib/action_controller/test_case.rb +160 -131
  65. data/lib/action_controller.rb +5 -1
  66. data/lib/action_dispatch/constants.rb +8 -0
  67. data/lib/action_dispatch/deprecator.rb +2 -0
  68. data/lib/action_dispatch/http/cache.rb +163 -35
  69. data/lib/action_dispatch/http/content_disposition.rb +2 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +54 -39
  71. data/lib/action_dispatch/http/filter_parameters.rb +14 -8
  72. data/lib/action_dispatch/http/filter_redirect.rb +22 -1
  73. data/lib/action_dispatch/http/headers.rb +22 -22
  74. data/lib/action_dispatch/http/mime_negotiation.rb +89 -41
  75. data/lib/action_dispatch/http/mime_type.rb +25 -21
  76. data/lib/action_dispatch/http/mime_types.rb +3 -0
  77. data/lib/action_dispatch/http/param_builder.rb +187 -0
  78. data/lib/action_dispatch/http/param_error.rb +26 -0
  79. data/lib/action_dispatch/http/parameters.rb +14 -12
  80. data/lib/action_dispatch/http/permissions_policy.rb +25 -36
  81. data/lib/action_dispatch/http/query_parser.rb +55 -0
  82. data/lib/action_dispatch/http/rack_cache.rb +2 -0
  83. data/lib/action_dispatch/http/request.rb +141 -92
  84. data/lib/action_dispatch/http/response.rb +137 -77
  85. data/lib/action_dispatch/http/upload.rb +18 -16
  86. data/lib/action_dispatch/http/url.rb +187 -89
  87. data/lib/action_dispatch/journey/formatter.rb +21 -9
  88. data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
  89. data/lib/action_dispatch/journey/gtg/simulator.rb +34 -11
  90. data/lib/action_dispatch/journey/gtg/transition_table.rb +47 -53
  91. data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
  92. data/lib/action_dispatch/journey/nodes/node.rb +8 -6
  93. data/lib/action_dispatch/journey/parser.rb +99 -195
  94. data/lib/action_dispatch/journey/path/pattern.rb +4 -1
  95. data/lib/action_dispatch/journey/route.rb +54 -38
  96. data/lib/action_dispatch/journey/router/utils.rb +22 -27
  97. data/lib/action_dispatch/journey/router.rb +63 -83
  98. data/lib/action_dispatch/journey/routes.rb +11 -2
  99. data/lib/action_dispatch/journey/scanner.rb +46 -42
  100. data/lib/action_dispatch/journey/visitors.rb +57 -23
  101. data/lib/action_dispatch/journey/visualizer/fsm.js +4 -6
  102. data/lib/action_dispatch/journey.rb +2 -0
  103. data/lib/action_dispatch/log_subscriber.rb +7 -1
  104. data/lib/action_dispatch/middleware/actionable_exceptions.rb +2 -0
  105. data/lib/action_dispatch/middleware/assume_ssl.rb +8 -5
  106. data/lib/action_dispatch/middleware/callbacks.rb +3 -1
  107. data/lib/action_dispatch/middleware/cookies.rb +125 -106
  108. data/lib/action_dispatch/middleware/debug_exceptions.rb +37 -8
  109. data/lib/action_dispatch/middleware/debug_locks.rb +15 -13
  110. data/lib/action_dispatch/middleware/debug_view.rb +13 -5
  111. data/lib/action_dispatch/middleware/exception_wrapper.rb +18 -23
  112. data/lib/action_dispatch/middleware/executor.rb +19 -4
  113. data/lib/action_dispatch/middleware/flash.rb +63 -51
  114. data/lib/action_dispatch/middleware/host_authorization.rb +17 -15
  115. data/lib/action_dispatch/middleware/public_exceptions.rb +14 -12
  116. data/lib/action_dispatch/middleware/reloader.rb +5 -3
  117. data/lib/action_dispatch/middleware/remote_ip.rb +87 -77
  118. data/lib/action_dispatch/middleware/request_id.rb +16 -10
  119. data/lib/action_dispatch/middleware/server_timing.rb +4 -2
  120. data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -0
  121. data/lib/action_dispatch/middleware/session/cache_store.rb +30 -8
  122. data/lib/action_dispatch/middleware/session/cookie_store.rb +27 -26
  123. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -3
  124. data/lib/action_dispatch/middleware/show_exceptions.rb +16 -16
  125. data/lib/action_dispatch/middleware/ssl.rb +53 -40
  126. data/lib/action_dispatch/middleware/stack.rb +11 -10
  127. data/lib/action_dispatch/middleware/static.rb +33 -31
  128. data/lib/action_dispatch/middleware/templates/rescues/_copy_button.html.erb +1 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +3 -5
  130. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +9 -5
  131. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +1 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +1 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +4 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +3 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +50 -0
  136. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -0
  137. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -0
  138. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -0
  139. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -0
  140. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -0
  141. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +1 -1
  142. data/lib/action_dispatch/railtie.rb +23 -3
  143. data/lib/action_dispatch/request/session.rb +24 -21
  144. data/lib/action_dispatch/request/utils.rb +11 -3
  145. data/lib/action_dispatch/routing/endpoint.rb +2 -0
  146. data/lib/action_dispatch/routing/inspector.rb +85 -60
  147. data/lib/action_dispatch/routing/mapper.rb +1031 -851
  148. data/lib/action_dispatch/routing/polymorphic_routes.rb +69 -62
  149. data/lib/action_dispatch/routing/redirection.rb +47 -39
  150. data/lib/action_dispatch/routing/route_set.rb +79 -56
  151. data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
  152. data/lib/action_dispatch/routing/url_for.rb +130 -125
  153. data/lib/action_dispatch/routing.rb +150 -148
  154. data/lib/action_dispatch/structured_event_subscriber.rb +20 -0
  155. data/lib/action_dispatch/system_test_case.rb +91 -81
  156. data/lib/action_dispatch/system_testing/browser.rb +16 -23
  157. data/lib/action_dispatch/system_testing/driver.rb +2 -0
  158. data/lib/action_dispatch/system_testing/server.rb +2 -0
  159. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +34 -23
  160. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
  161. data/lib/action_dispatch/testing/assertion_response.rb +9 -7
  162. data/lib/action_dispatch/testing/assertions/response.rb +52 -25
  163. data/lib/action_dispatch/testing/assertions/routing.rb +168 -87
  164. data/lib/action_dispatch/testing/assertions.rb +2 -0
  165. data/lib/action_dispatch/testing/integration.rb +233 -223
  166. data/lib/action_dispatch/testing/request_encoder.rb +11 -9
  167. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  168. data/lib/action_dispatch/testing/test_process.rb +11 -8
  169. data/lib/action_dispatch/testing/test_request.rb +3 -1
  170. data/lib/action_dispatch/testing/test_response.rb +27 -26
  171. data/lib/action_dispatch.rb +36 -32
  172. data/lib/action_pack/gem_version.rb +6 -4
  173. data/lib/action_pack/version.rb +3 -1
  174. data/lib/action_pack.rb +17 -16
  175. metadata +36 -32
  176. data/lib/action_dispatch/journey/parser.y +0 -50
  177. data/lib/action_dispatch/journey/parser_extras.rb +0 -31
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "active_support/core_ext/module/attribute_accessors"
4
6
  require "active_support/syntax_error_proxy"
5
7
  require "active_support/core_ext/thread/backtrace/location"
@@ -16,11 +18,12 @@ module ActionDispatch
16
18
  "ActionController::UnknownFormat" => :not_acceptable,
17
19
  "ActionDispatch::Http::MimeNegotiation::InvalidType" => :not_acceptable,
18
20
  "ActionController::MissingExactTemplate" => :not_acceptable,
19
- "ActionController::InvalidAuthenticityToken" => :unprocessable_entity,
20
- "ActionController::InvalidCrossOriginRequest" => :unprocessable_entity,
21
+ "ActionController::InvalidAuthenticityToken" => ActionDispatch::Constants::UNPROCESSABLE_CONTENT,
22
+ "ActionController::InvalidCrossOriginRequest" => ActionDispatch::Constants::UNPROCESSABLE_CONTENT,
21
23
  "ActionDispatch::Http::Parameters::ParseError" => :bad_request,
22
24
  "ActionController::BadRequest" => :bad_request,
23
25
  "ActionController::ParameterMissing" => :bad_request,
26
+ "ActionController::TooManyRequests" => :too_many_requests,
24
27
  "Rack::QueryParser::ParameterTypeError" => :bad_request,
25
28
  "Rack::QueryParser::InvalidParameterError" => :bad_request
26
29
  )
@@ -146,15 +149,20 @@ module ActionDispatch
146
149
  application_trace_with_ids = []
147
150
  framework_trace_with_ids = []
148
151
  full_trace_with_ids = []
152
+ application_traces = application_trace.map(&:to_s)
149
153
 
154
+ full_trace = backtrace_cleaner&.clean_locations(backtrace, :all).presence || backtrace
150
155
  full_trace.each_with_index do |trace, idx|
156
+ filtered_trace = backtrace_cleaner&.clean_frame(trace, :all) || trace
157
+
151
158
  trace_with_id = {
152
159
  exception_object_id: @exception.object_id,
153
160
  id: idx,
154
- trace: trace
161
+ trace: trace,
162
+ filtered_trace: filtered_trace,
155
163
  }
156
164
 
157
- if application_trace.include?(trace)
165
+ if application_traces.include?(filtered_trace.to_s)
158
166
  application_trace_with_ids << trace_with_id
159
167
  else
160
168
  framework_trace_with_ids << trace_with_id
@@ -171,27 +179,19 @@ module ActionDispatch
171
179
  end
172
180
 
173
181
  def self.status_code_for_exception(class_name)
174
- Rack::Utils.status_code(@@rescue_responses[class_name])
182
+ ActionDispatch::Response.rack_status_code(@@rescue_responses[class_name])
175
183
  end
176
184
 
177
185
  def show?(request)
178
- # We're treating `nil` as "unset", and we want the default setting to be
179
- # `:all`. This logic should be extracted to `env_config` and calculated
180
- # once.
186
+ # We're treating `nil` as "unset", and we want the default setting to be `:all`.
187
+ # This logic should be extracted to `env_config` and calculated once.
181
188
  config = request.get_header("action_dispatch.show_exceptions")
182
189
 
183
- # Include true and false for backwards compatibility.
184
190
  case config
185
191
  when :none
186
192
  false
187
193
  when :rescuable
188
194
  rescue_response?
189
- when true
190
- ActionDispatch.deprecator.warn("Setting action_dispatch.show_exceptions to true is deprecated. Set to :all instead.")
191
- true
192
- when false
193
- ActionDispatch.deprecator.warn("Setting action_dispatch.show_exceptions to false is deprecated. Set to :none instead.")
194
- false
195
195
  else
196
196
  true
197
197
  end
@@ -203,15 +203,10 @@ module ActionDispatch
203
203
 
204
204
  def source_extracts
205
205
  backtrace.map do |trace|
206
- extract_source(trace)
206
+ extract_source(trace).merge(trace: trace)
207
207
  end
208
208
  end
209
209
 
210
- def error_highlight_available?
211
- # ErrorHighlight.spot with backtrace_location keyword is available since error_highlight 0.4.0
212
- defined?(ErrorHighlight) && Gem::Version.new(ErrorHighlight::VERSION) >= Gem::Version.new("0.4.0")
213
- end
214
-
215
210
  def trace_to_show
216
211
  if traces["Application Trace"].empty? && rescue_template != "routing_error"
217
212
  "Full Trace"
@@ -272,13 +267,13 @@ module ActionDispatch
272
267
  end
273
268
 
274
269
  (@exception.backtrace_locations || []).map do |loc|
275
- if built_methods.key?(loc.label.to_s)
270
+ if built_methods.key?(loc.base_label)
276
271
  thread_backtrace_location = if loc.respond_to?(:__getobj__)
277
272
  loc.__getobj__
278
273
  else
279
274
  loc
280
275
  end
281
- SourceMapLocation.new(thread_backtrace_location, built_methods[loc.label.to_s])
276
+ SourceMapLocation.new(thread_backtrace_location, built_methods[loc.base_label])
282
277
  else
283
278
  loc
284
279
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "rack/body_proxy"
4
6
 
5
7
  module ActionDispatch
@@ -10,6 +12,10 @@ module ActionDispatch
10
12
 
11
13
  def call(env)
12
14
  state = @executor.run!(reset: true)
15
+ if response_finished = env["rack.response_finished"]
16
+ response_finished << proc { state.complete! }
17
+ end
18
+
13
19
  begin
14
20
  response = @app.call(env)
15
21
 
@@ -18,12 +24,21 @@ module ActionDispatch
18
24
  @executor.error_reporter.report(error, handled: false, source: "application.action_dispatch")
19
25
  end
20
26
 
21
- returned = response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
22
- rescue => error
23
- @executor.error_reporter.report(error, handled: false, source: "application.action_dispatch")
27
+ unless response_finished
28
+ response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
29
+ end
30
+ returned = true
31
+ response
32
+ rescue Exception => error
33
+ request = ActionDispatch::Request.new env
34
+ backtrace_cleaner = request.get_header("action_dispatch.backtrace_cleaner")
35
+ wrapper = ExceptionWrapper.new(backtrace_cleaner, error)
36
+ @executor.error_reporter.report(wrapper.unwrapped_exception, handled: false, source: "application.action_dispatch")
24
37
  raise
25
38
  ensure
26
- state.complete! unless returned
39
+ if !returned && !response_finished
40
+ state.complete!
41
+ end
27
42
  end
28
43
  end
29
44
  end
@@ -1,41 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "active_support/core_ext/hash/keys"
4
6
 
5
7
  module ActionDispatch
6
- # = Action Dispatch \Flash
8
+ # # Action Dispatch Flash
7
9
  #
8
- # The flash provides a way to pass temporary primitive-types (String, Array, Hash) between actions. Anything you place in the flash will be exposed
9
- # to the very next action and then cleared out. This is a great way of doing notices and alerts, such as a create
10
- # action that sets <tt>flash[:notice] = "Post successfully created"</tt> before redirecting to a display action that can
11
- # then expose the flash to its template. Actually, that exposure is automatically done.
10
+ # The flash provides a way to pass temporary primitive-types (String, Array,
11
+ # Hash) between actions. Anything you place in the flash will be exposed to the
12
+ # very next action and then cleared out. This is a great way of doing notices
13
+ # and alerts, such as a create action that sets `flash[:notice] = "Post
14
+ # successfully created"` before redirecting to a display action that can then
15
+ # expose the flash to its template. Actually, that exposure is automatically
16
+ # done.
12
17
  #
13
- # class PostsController < ActionController::Base
14
- # def create
15
- # # save post
16
- # flash[:notice] = "Post successfully created"
17
- # redirect_to @post
18
- # end
18
+ # class PostsController < ActionController::Base
19
+ # def create
20
+ # # save post
21
+ # flash[:notice] = "Post successfully created"
22
+ # redirect_to @post
23
+ # end
19
24
  #
20
- # def show
21
- # # doesn't need to assign the flash notice to the template, that's done automatically
25
+ # def show
26
+ # # doesn't need to assign the flash notice to the template, that's done automatically
27
+ # end
22
28
  # end
23
- # end
24
29
  #
25
- # Then in +show.html.erb+:
30
+ # Then in `show.html.erb`:
26
31
  #
27
- # <% if flash[:notice] %>
28
- # <div class="notice"><%= flash[:notice] %></div>
29
- # <% end %>
32
+ # <% if flash[:notice] %>
33
+ # <div class="notice"><%= flash[:notice] %></div>
34
+ # <% end %>
30
35
  #
31
- # Since the +notice+ and +alert+ keys are a common idiom, convenience accessors are available:
36
+ # Since the `notice` and `alert` keys are a common idiom, convenience accessors
37
+ # are available:
32
38
  #
33
- # flash.alert = "You must be logged in"
34
- # flash.notice = "Post successfully created"
39
+ # flash.alert = "You must be logged in"
40
+ # flash.notice = "Post successfully created"
35
41
  #
36
- # This example places a string in the flash. And of course, you can put as many as you like at a time too. If you want to pass
37
- # non-primitive types, you will have to handle that in your application. Example: To show messages with links, you will have to
38
- # use sanitize helper.
42
+ # This example places a string in the flash. And of course, you can put as many
43
+ # as you like at a time too. If you want to pass non-primitive types, you will
44
+ # have to handle that in your application. Example: To show messages with links,
45
+ # you will have to use sanitize helper.
39
46
  #
40
47
  # Just remember: They'll be gone by the time the next action has been performed.
41
48
  #
@@ -98,12 +105,12 @@ module ActionDispatch
98
105
  @flash[k.to_s]
99
106
  end
100
107
 
101
- # Convenience accessor for <tt>flash.now[:alert]=</tt>.
108
+ # Convenience accessor for `flash.now[:alert]=`.
102
109
  def alert=(message)
103
110
  self[:alert] = message
104
111
  end
105
112
 
106
- # Convenience accessor for <tt>flash.now[:notice]=</tt>.
113
+ # Convenience accessor for `flash.now[:notice]=`.
107
114
  def notice=(message)
108
115
  self[:notice] = message
109
116
  end
@@ -131,8 +138,8 @@ module ActionDispatch
131
138
  end
132
139
  end
133
140
 
134
- # Builds a hash containing the flashes to keep for the next request.
135
- # If there are none to keep, returns +nil+.
141
+ # Builds a hash containing the flashes to keep for the next request. If there
142
+ # are none to keep, returns `nil`.
136
143
  def to_session_value # :nodoc:
137
144
  flashes_to_keep = @flashes.except(*@discard)
138
145
  return nil if flashes_to_keep.empty?
@@ -177,8 +184,8 @@ module ActionDispatch
177
184
  @flashes.key? name.to_s
178
185
  end
179
186
 
180
- # Immediately deletes the single flash entry. Use this method when you
181
- # want remove the message within the current action. See also #discard.
187
+ # Immediately deletes the single flash entry. Use this method when you want
188
+ # remove the message within the current action. See also #discard.
182
189
  def delete(key)
183
190
  key = key.to_s
184
191
  @discard.delete key
@@ -211,45 +218,49 @@ module ActionDispatch
211
218
  self
212
219
  end
213
220
 
214
- # Sets a flash that will not be available to the next action, only to the current.
221
+ # Sets a flash that will not be available to the next action, only to the
222
+ # current.
215
223
  #
216
224
  # flash.now[:message] = "Hello current action"
217
225
  #
218
- # This method enables you to use the flash as a central messaging system in your app.
219
- # When you need to pass an object to the next action, you use the standard flash assign (<tt>[]=</tt>).
220
- # When you need to pass an object to the current action, you use <tt>now</tt>, and your object will
221
- # vanish when the current action is done.
226
+ # This method enables you to use the flash as a central messaging system in your
227
+ # app. When you need to pass an object to the next action, you use the standard
228
+ # flash assign (`[]=`). When you need to pass an object to the current action,
229
+ # you use `now`, and your object will vanish when the current action is done.
222
230
  #
223
- # Entries set via <tt>now</tt> are accessed the same way as standard entries: <tt>flash['my-key']</tt>.
231
+ # Entries set via `now` are accessed the same way as standard entries:
232
+ # `flash['my-key']`.
224
233
  #
225
234
  # Also, brings two convenience accessors:
226
235
  #
227
- # flash.now.alert = "Beware now!"
228
- # # Equivalent to flash.now[:alert] = "Beware now!"
236
+ # flash.now.alert = "Beware now!"
237
+ # # Equivalent to flash.now[:alert] = "Beware now!"
229
238
  #
230
- # flash.now.notice = "Good luck now!"
231
- # # Equivalent to flash.now[:notice] = "Good luck now!"
239
+ # flash.now.notice = "Good luck now!"
240
+ # # Equivalent to flash.now[:notice] = "Good luck now!"
232
241
  def now
233
242
  @now ||= FlashNow.new(self)
234
243
  end
235
244
 
236
- # Keeps either the entire current flash or a specific flash entry available for the next action:
245
+ # Keeps either the entire current flash or a specific flash entry available for
246
+ # the next action:
237
247
  #
238
- # flash.keep # keeps the entire flash
239
- # flash.keep(:notice) # keeps only the "notice" entry, the rest of the flash is discarded
248
+ # flash.keep # keeps the entire flash
249
+ # flash.keep(:notice) # keeps only the "notice" entry, the rest of the flash is discarded
240
250
  def keep(k = nil)
241
251
  k = k.to_s if k
242
252
  @discard.subtract Array(k || keys)
243
253
  k ? self[k] : self
244
254
  end
245
255
 
246
- # Marks the entire flash or a single flash entry to be discarded by the end of the current action:
256
+ # Marks the entire flash or a single flash entry to be discarded by the end of
257
+ # the current action:
247
258
  #
248
259
  # flash.discard # discard the entire flash at the end of the current action
249
260
  # flash.discard(:warning) # discard only the "warning" entry at the end of the current action
250
261
  #
251
- # Use this method when you want to display the message in the current
252
- # action but not in the next one. See also #delete.
262
+ # Use this method when you want to display the message in the current action but
263
+ # not in the next one. See also #delete.
253
264
  def discard(k = nil)
254
265
  k = k.to_s if k
255
266
  @discard.merge Array(k || keys)
@@ -258,28 +269,29 @@ module ActionDispatch
258
269
 
259
270
  # Mark for removal entries that were kept, and delete unkept ones.
260
271
  #
261
- # This method is called automatically by filters, so you generally don't need to care about it.
272
+ # This method is called automatically by filters, so you generally don't need to
273
+ # care about it.
262
274
  def sweep # :nodoc:
263
275
  @discard.each { |k| @flashes.delete k }
264
276
  @discard.replace @flashes.keys
265
277
  end
266
278
 
267
- # Convenience accessor for <tt>flash[:alert]</tt>.
279
+ # Convenience accessor for `flash[:alert]`.
268
280
  def alert
269
281
  self[:alert]
270
282
  end
271
283
 
272
- # Convenience accessor for <tt>flash[:alert]=</tt>.
284
+ # Convenience accessor for `flash[:alert]=`.
273
285
  def alert=(message)
274
286
  self[:alert] = message
275
287
  end
276
288
 
277
- # Convenience accessor for <tt>flash[:notice]</tt>.
289
+ # Convenience accessor for `flash[:notice]`.
278
290
  def notice
279
291
  self[:notice]
280
292
  end
281
293
 
282
- # Convenience accessor for <tt>flash[:notice]=</tt>.
294
+ # Convenience accessor for `flash[:notice]=`.
283
295
  def notice=(message)
284
296
  self[:notice] = message
285
297
  end
@@ -1,24 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionDispatch
4
- # = Action Dispatch \HostAuthorization
6
+ # # Action Dispatch HostAuthorization
5
7
  #
6
- # This middleware guards from DNS rebinding attacks by explicitly permitting
7
- # the hosts a request can be sent to, and is passed the options set in
8
- # +config.host_authorization+.
8
+ # This middleware guards from DNS rebinding attacks by explicitly permitting the
9
+ # hosts a request can be sent to, and is passed the options set in
10
+ # `config.host_authorization`.
9
11
  #
10
- # Requests can opt-out of Host Authorization with +exclude+:
12
+ # Requests can opt-out of Host Authorization with `exclude`:
11
13
  #
12
- # config.host_authorization = { exclude: ->(request) { request.path =~ /healthcheck/ } }
14
+ # config.host_authorization = { exclude: ->(request) { request.path =~ /healthcheck/ } }
13
15
  #
14
- # When a request comes to an unauthorized host, the +response_app+
15
- # application will be executed and rendered. If no +response_app+ is given, a
16
- # default one will run.
17
- # The default response app logs blocked host info with level 'error' and
18
- # responds with <tt>403 Forbidden</tt>. The body of the response contains debug info
19
- # if +config.consider_all_requests_local+ is set to true, otherwise the body is empty.
16
+ # When a request comes to an unauthorized host, the `response_app` application
17
+ # will be executed and rendered. If no `response_app` is given, a default one
18
+ # will run. The default response app logs blocked host info with level 'error'
19
+ # and responds with `403 Forbidden`. The body of the response contains debug
20
+ # info if `config.consider_all_requests_local` is set to true, otherwise the
21
+ # body is empty.
20
22
  class HostAuthorization
21
- ALLOWED_HOSTS_IN_DEVELOPMENT = [".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")]
23
+ ALLOWED_HOSTS_IN_DEVELOPMENT = [".localhost", ".test", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")]
22
24
  PORT_REGEX = /(?::\d+)/ # :nodoc:
23
25
  SUBDOMAIN_REGEX = /(?:[a-z0-9-]+\.)/i # :nodoc:
24
26
  IPV4_HOSTNAME = /(?<host>\d+\.\d+\.\d+\.\d+)#{PORT_REGEX}?/ # :nodoc:
@@ -45,8 +47,8 @@ module ActionDispatch
45
47
  begin
46
48
  allowed === extract_hostname(host)
47
49
  rescue
48
- # IPAddr#=== raises an error if you give it a hostname instead of
49
- # IP. Treat similar errors as blocked access.
50
+ # IPAddr#=== raises an error if you give it a hostname instead of IP. Treat
51
+ # similar errors as blocked access.
50
52
  false
51
53
  end
52
54
  else
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionDispatch
4
- # = Action Dispatch \PublicExceptions
6
+ # # Action Dispatch PublicExceptions
5
7
  #
6
8
  # When called, this middleware renders an error page. By default if an HTML
7
- # response is expected it will render static error pages from the <tt>/public</tt>
9
+ # response is expected it will render static error pages from the `/public`
8
10
  # directory. For example when this middleware receives a 500 response it will
9
- # render the template found in <tt>/public/500.html</tt>.
10
- # If an internationalized locale is set, this middleware will attempt to render
11
- # the template in <tt>/public/500.<locale>.html</tt>. If an internationalized template
12
- # is not found it will fall back on <tt>/public/500.html</tt>.
11
+ # render the template found in `/public/500.html`. If an internationalized
12
+ # locale is set, this middleware will attempt to render the template in
13
+ # `/public/500.<locale>.html`. If an internationalized template is not found it
14
+ # will fall back on `/public/500.html`.
13
15
  #
14
16
  # When a request with a content type other than HTML is made, this middleware
15
17
  # will attempt to convert error information into the appropriate response type.
@@ -23,14 +25,14 @@ module ActionDispatch
23
25
  def call(env)
24
26
  request = ActionDispatch::Request.new(env)
25
27
  status = request.path_info[1..-1].to_i
26
- begin
27
- content_type = request.formats.first
28
- rescue ActionDispatch::Http::MimeNegotiation::InvalidType
29
- content_type = Mime[:text]
30
- end
28
+ content_type = request.formats.first
31
29
  body = { status: status, error: Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500]) }
32
30
 
33
- render(status, content_type, body)
31
+ if env["action_dispatch.original_request_method"] == "HEAD"
32
+ render_format(status, content_type, "")
33
+ else
34
+ render(status, content_type, body)
35
+ end
34
36
  end
35
37
 
36
38
  private
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionDispatch
4
- # = Action Dispatch \Reloader
6
+ # # Action Dispatch Reloader
5
7
  #
6
8
  # ActionDispatch::Reloader wraps the request with callbacks provided by
7
9
  # ActiveSupport::Reloader, intended to assist with code reloading during
8
10
  # development.
9
11
  #
10
- # ActionDispatch::Reloader is included in the middleware stack only if
11
- # reloading is enabled, which it is by the default in +development+ mode.
12
+ # ActionDispatch::Reloader is included in the middleware stack only if reloading
13
+ # is enabled, which it is by the default in `development` mode.
12
14
  class Reloader < Executor
13
15
  end
14
16
  end