omg-actionpack 8.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +129 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README.rdoc +57 -0
  5. data/lib/abstract_controller/asset_paths.rb +14 -0
  6. data/lib/abstract_controller/base.rb +299 -0
  7. data/lib/abstract_controller/caching/fragments.rb +149 -0
  8. data/lib/abstract_controller/caching.rb +68 -0
  9. data/lib/abstract_controller/callbacks.rb +265 -0
  10. data/lib/abstract_controller/collector.rb +44 -0
  11. data/lib/abstract_controller/deprecator.rb +9 -0
  12. data/lib/abstract_controller/error.rb +8 -0
  13. data/lib/abstract_controller/helpers.rb +243 -0
  14. data/lib/abstract_controller/logger.rb +16 -0
  15. data/lib/abstract_controller/railties/routes_helpers.rb +25 -0
  16. data/lib/abstract_controller/rendering.rb +126 -0
  17. data/lib/abstract_controller/translation.rb +42 -0
  18. data/lib/abstract_controller/url_for.rb +37 -0
  19. data/lib/abstract_controller.rb +36 -0
  20. data/lib/action_controller/api/api_rendering.rb +18 -0
  21. data/lib/action_controller/api.rb +155 -0
  22. data/lib/action_controller/base.rb +332 -0
  23. data/lib/action_controller/caching.rb +49 -0
  24. data/lib/action_controller/deprecator.rb +9 -0
  25. data/lib/action_controller/form_builder.rb +55 -0
  26. data/lib/action_controller/log_subscriber.rb +96 -0
  27. data/lib/action_controller/metal/allow_browser.rb +123 -0
  28. data/lib/action_controller/metal/basic_implicit_render.rb +17 -0
  29. data/lib/action_controller/metal/conditional_get.rb +341 -0
  30. data/lib/action_controller/metal/content_security_policy.rb +86 -0
  31. data/lib/action_controller/metal/cookies.rb +20 -0
  32. data/lib/action_controller/metal/data_streaming.rb +154 -0
  33. data/lib/action_controller/metal/default_headers.rb +21 -0
  34. data/lib/action_controller/metal/etag_with_flash.rb +22 -0
  35. data/lib/action_controller/metal/etag_with_template_digest.rb +59 -0
  36. data/lib/action_controller/metal/exceptions.rb +106 -0
  37. data/lib/action_controller/metal/flash.rb +67 -0
  38. data/lib/action_controller/metal/head.rb +67 -0
  39. data/lib/action_controller/metal/helpers.rb +129 -0
  40. data/lib/action_controller/metal/http_authentication.rb +565 -0
  41. data/lib/action_controller/metal/implicit_render.rb +67 -0
  42. data/lib/action_controller/metal/instrumentation.rb +120 -0
  43. data/lib/action_controller/metal/live.rb +398 -0
  44. data/lib/action_controller/metal/logging.rb +22 -0
  45. data/lib/action_controller/metal/mime_responds.rb +337 -0
  46. data/lib/action_controller/metal/parameter_encoding.rb +84 -0
  47. data/lib/action_controller/metal/params_wrapper.rb +312 -0
  48. data/lib/action_controller/metal/permissions_policy.rb +38 -0
  49. data/lib/action_controller/metal/rate_limiting.rb +62 -0
  50. data/lib/action_controller/metal/redirecting.rb +251 -0
  51. data/lib/action_controller/metal/renderers.rb +181 -0
  52. data/lib/action_controller/metal/rendering.rb +260 -0
  53. data/lib/action_controller/metal/request_forgery_protection.rb +667 -0
  54. data/lib/action_controller/metal/rescue.rb +33 -0
  55. data/lib/action_controller/metal/streaming.rb +183 -0
  56. data/lib/action_controller/metal/strong_parameters.rb +1546 -0
  57. data/lib/action_controller/metal/testing.rb +25 -0
  58. data/lib/action_controller/metal/url_for.rb +65 -0
  59. data/lib/action_controller/metal.rb +339 -0
  60. data/lib/action_controller/railtie.rb +149 -0
  61. data/lib/action_controller/railties/helpers.rb +26 -0
  62. data/lib/action_controller/renderer.rb +161 -0
  63. data/lib/action_controller/template_assertions.rb +13 -0
  64. data/lib/action_controller/test_case.rb +691 -0
  65. data/lib/action_controller.rb +80 -0
  66. data/lib/action_dispatch/constants.rb +34 -0
  67. data/lib/action_dispatch/deprecator.rb +9 -0
  68. data/lib/action_dispatch/http/cache.rb +249 -0
  69. data/lib/action_dispatch/http/content_disposition.rb +47 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +365 -0
  71. data/lib/action_dispatch/http/filter_parameters.rb +80 -0
  72. data/lib/action_dispatch/http/filter_redirect.rb +50 -0
  73. data/lib/action_dispatch/http/headers.rb +134 -0
  74. data/lib/action_dispatch/http/mime_negotiation.rb +187 -0
  75. data/lib/action_dispatch/http/mime_type.rb +389 -0
  76. data/lib/action_dispatch/http/mime_types.rb +54 -0
  77. data/lib/action_dispatch/http/parameters.rb +119 -0
  78. data/lib/action_dispatch/http/permissions_policy.rb +189 -0
  79. data/lib/action_dispatch/http/rack_cache.rb +67 -0
  80. data/lib/action_dispatch/http/request.rb +498 -0
  81. data/lib/action_dispatch/http/response.rb +556 -0
  82. data/lib/action_dispatch/http/upload.rb +107 -0
  83. data/lib/action_dispatch/http/url.rb +344 -0
  84. data/lib/action_dispatch/journey/formatter.rb +226 -0
  85. data/lib/action_dispatch/journey/gtg/builder.rb +149 -0
  86. data/lib/action_dispatch/journey/gtg/simulator.rb +50 -0
  87. data/lib/action_dispatch/journey/gtg/transition_table.rb +217 -0
  88. data/lib/action_dispatch/journey/nfa/dot.rb +27 -0
  89. data/lib/action_dispatch/journey/nodes/node.rb +208 -0
  90. data/lib/action_dispatch/journey/parser.rb +103 -0
  91. data/lib/action_dispatch/journey/path/pattern.rb +209 -0
  92. data/lib/action_dispatch/journey/route.rb +189 -0
  93. data/lib/action_dispatch/journey/router/utils.rb +105 -0
  94. data/lib/action_dispatch/journey/router.rb +151 -0
  95. data/lib/action_dispatch/journey/routes.rb +82 -0
  96. data/lib/action_dispatch/journey/scanner.rb +70 -0
  97. data/lib/action_dispatch/journey/visitors.rb +267 -0
  98. data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
  99. data/lib/action_dispatch/journey/visualizer/fsm.js +159 -0
  100. data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
  101. data/lib/action_dispatch/journey.rb +7 -0
  102. data/lib/action_dispatch/log_subscriber.rb +25 -0
  103. data/lib/action_dispatch/middleware/actionable_exceptions.rb +46 -0
  104. data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
  105. data/lib/action_dispatch/middleware/callbacks.rb +38 -0
  106. data/lib/action_dispatch/middleware/cookies.rb +719 -0
  107. data/lib/action_dispatch/middleware/debug_exceptions.rb +206 -0
  108. data/lib/action_dispatch/middleware/debug_locks.rb +129 -0
  109. data/lib/action_dispatch/middleware/debug_view.rb +73 -0
  110. data/lib/action_dispatch/middleware/exception_wrapper.rb +350 -0
  111. data/lib/action_dispatch/middleware/executor.rb +32 -0
  112. data/lib/action_dispatch/middleware/flash.rb +318 -0
  113. data/lib/action_dispatch/middleware/host_authorization.rb +171 -0
  114. data/lib/action_dispatch/middleware/public_exceptions.rb +64 -0
  115. data/lib/action_dispatch/middleware/reloader.rb +16 -0
  116. data/lib/action_dispatch/middleware/remote_ip.rb +199 -0
  117. data/lib/action_dispatch/middleware/request_id.rb +50 -0
  118. data/lib/action_dispatch/middleware/server_timing.rb +78 -0
  119. data/lib/action_dispatch/middleware/session/abstract_store.rb +112 -0
  120. data/lib/action_dispatch/middleware/session/cache_store.rb +66 -0
  121. data/lib/action_dispatch/middleware/session/cookie_store.rb +129 -0
  122. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +34 -0
  123. data/lib/action_dispatch/middleware/show_exceptions.rb +88 -0
  124. data/lib/action_dispatch/middleware/ssl.rb +180 -0
  125. data/lib/action_dispatch/middleware/stack.rb +194 -0
  126. data/lib/action_dispatch/middleware/static.rb +192 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
  128. data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +22 -0
  130. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +17 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +36 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +62 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
  136. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +12 -0
  137. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +9 -0
  138. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +35 -0
  139. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
  140. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +24 -0
  141. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +16 -0
  142. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +284 -0
  143. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +23 -0
  144. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb +3 -0
  145. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
  146. data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
  147. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
  148. data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
  149. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
  150. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
  151. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
  152. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
  153. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +19 -0
  154. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +232 -0
  155. data/lib/action_dispatch/railtie.rb +77 -0
  156. data/lib/action_dispatch/request/session.rb +283 -0
  157. data/lib/action_dispatch/request/utils.rb +109 -0
  158. data/lib/action_dispatch/routing/endpoint.rb +19 -0
  159. data/lib/action_dispatch/routing/inspector.rb +323 -0
  160. data/lib/action_dispatch/routing/mapper.rb +2372 -0
  161. data/lib/action_dispatch/routing/polymorphic_routes.rb +363 -0
  162. data/lib/action_dispatch/routing/redirection.rb +218 -0
  163. data/lib/action_dispatch/routing/route_set.rb +958 -0
  164. data/lib/action_dispatch/routing/routes_proxy.rb +66 -0
  165. data/lib/action_dispatch/routing/url_for.rb +244 -0
  166. data/lib/action_dispatch/routing.rb +262 -0
  167. data/lib/action_dispatch/system_test_case.rb +206 -0
  168. data/lib/action_dispatch/system_testing/browser.rb +75 -0
  169. data/lib/action_dispatch/system_testing/driver.rb +85 -0
  170. data/lib/action_dispatch/system_testing/server.rb +33 -0
  171. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +164 -0
  172. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +23 -0
  173. data/lib/action_dispatch/testing/assertion_response.rb +48 -0
  174. data/lib/action_dispatch/testing/assertions/response.rb +114 -0
  175. data/lib/action_dispatch/testing/assertions/routing.rb +343 -0
  176. data/lib/action_dispatch/testing/assertions.rb +25 -0
  177. data/lib/action_dispatch/testing/integration.rb +694 -0
  178. data/lib/action_dispatch/testing/request_encoder.rb +60 -0
  179. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  180. data/lib/action_dispatch/testing/test_process.rb +57 -0
  181. data/lib/action_dispatch/testing/test_request.rb +73 -0
  182. data/lib/action_dispatch/testing/test_response.rb +58 -0
  183. data/lib/action_dispatch.rb +147 -0
  184. data/lib/action_pack/gem_version.rb +19 -0
  185. data/lib/action_pack/version.rb +12 -0
  186. data/lib/action_pack.rb +27 -0
  187. metadata +375 -0
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :markup: markdown
4
+
5
+ module ActionController
6
+ module Testing
7
+ # Behavior specific to functional tests
8
+ module Functional # :nodoc:
9
+ def clear_instance_variables_between_requests
10
+ if defined?(@_ivars)
11
+ new_ivars = instance_variables - @_ivars
12
+ new_ivars.each { |ivar| remove_instance_variable(ivar) }
13
+ end
14
+
15
+ @_ivars = instance_variables
16
+ end
17
+
18
+ def recycle!
19
+ @_url_options = nil
20
+ self.formats = nil
21
+ self.params = nil
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :markup: markdown
4
+
5
+ module ActionController
6
+ # # Action Controller UrlFor
7
+ #
8
+ # Includes `url_for` into the host class. The class has to provide a `RouteSet`
9
+ # by implementing the `_routes` method. Otherwise, an exception will be raised.
10
+ #
11
+ # In addition to AbstractController::UrlFor, this module accesses the HTTP layer
12
+ # to define URL options like the `host`. In order to do so, this module requires
13
+ # the host class to implement `env` which needs to be Rack-compatible, and
14
+ # `request` which returns an ActionDispatch::Request instance.
15
+ #
16
+ # class RootUrl
17
+ # include ActionController::UrlFor
18
+ # include Rails.application.routes.url_helpers
19
+ #
20
+ # delegate :env, :request, to: :controller
21
+ #
22
+ # def initialize(controller)
23
+ # @controller = controller
24
+ # @url = root_path # named route from the application.
25
+ # end
26
+ # end
27
+ module UrlFor
28
+ extend ActiveSupport::Concern
29
+
30
+ include AbstractController::UrlFor
31
+
32
+ def initialize(...)
33
+ super
34
+ @_url_options = nil
35
+ end
36
+
37
+ def url_options
38
+ @_url_options ||= {
39
+ host: request.host,
40
+ port: request.optional_port,
41
+ protocol: request.protocol,
42
+ _recall: request.path_parameters
43
+ }.merge!(super).freeze
44
+
45
+ if (same_origin = _routes.equal?(request.routes)) ||
46
+ (script_name = request.engine_script_name(_routes)) ||
47
+ (original_script_name = request.original_script_name)
48
+
49
+ options = @_url_options.dup
50
+ if original_script_name
51
+ options[:original_script_name] = original_script_name
52
+ else
53
+ if same_origin
54
+ options[:script_name] = request.script_name.empty? ? "" : request.script_name.dup
55
+ else
56
+ options[:script_name] = script_name
57
+ end
58
+ end
59
+ options.freeze
60
+ else
61
+ @_url_options
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,339 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :markup: markdown
4
+
5
+ require "active_support/core_ext/array/extract_options"
6
+ require "action_dispatch/middleware/stack"
7
+
8
+ module ActionController
9
+ # # Action Controller MiddlewareStack
10
+ #
11
+ # Extend ActionDispatch middleware stack to make it aware of options allowing
12
+ # the following syntax in controllers:
13
+ #
14
+ # class PostsController < ApplicationController
15
+ # use AuthenticationMiddleware, except: [:index, :show]
16
+ # end
17
+ #
18
+ class MiddlewareStack < ActionDispatch::MiddlewareStack # :nodoc:
19
+ class Middleware < ActionDispatch::MiddlewareStack::Middleware # :nodoc:
20
+ def initialize(klass, args, actions, strategy, block)
21
+ @actions = actions
22
+ @strategy = strategy
23
+ super(klass, args, block)
24
+ end
25
+
26
+ def valid?(action)
27
+ @strategy.call @actions, action
28
+ end
29
+ end
30
+
31
+ def build(action, app = nil, &block)
32
+ action = action.to_s
33
+
34
+ middlewares.reverse.inject(app || block) do |a, middleware|
35
+ middleware.valid?(action) ? middleware.build(a) : a
36
+ end
37
+ end
38
+
39
+ private
40
+ INCLUDE = ->(list, action) { list.include? action }
41
+ EXCLUDE = ->(list, action) { !list.include? action }
42
+ NULL = ->(list, action) { true }
43
+
44
+ def build_middleware(klass, args, block)
45
+ options = args.extract_options!
46
+ only = Array(options.delete(:only)).map(&:to_s)
47
+ except = Array(options.delete(:except)).map(&:to_s)
48
+ args << options unless options.empty?
49
+
50
+ strategy = NULL
51
+ list = nil
52
+
53
+ if only.any?
54
+ strategy = INCLUDE
55
+ list = only
56
+ elsif except.any?
57
+ strategy = EXCLUDE
58
+ list = except
59
+ end
60
+
61
+ Middleware.new(klass, args, list, strategy, block)
62
+ end
63
+ end
64
+
65
+ # # Action Controller Metal
66
+ #
67
+ # `ActionController::Metal` is the simplest possible controller, providing a
68
+ # valid Rack interface without the additional niceties provided by
69
+ # ActionController::Base.
70
+ #
71
+ # A sample metal controller might look like this:
72
+ #
73
+ # class HelloController < ActionController::Metal
74
+ # def index
75
+ # self.response_body = "Hello World!"
76
+ # end
77
+ # end
78
+ #
79
+ # And then to route requests to your metal controller, you would add something
80
+ # like this to `config/routes.rb`:
81
+ #
82
+ # get 'hello', to: HelloController.action(:index)
83
+ #
84
+ # The ::action method returns a valid Rack application for the Rails router to
85
+ # dispatch to.
86
+ #
87
+ # ## Rendering Helpers
88
+ #
89
+ # By default, `ActionController::Metal` provides no utilities for rendering
90
+ # views, partials, or other responses aside from some low-level setters such
91
+ # as #response_body=, #content_type=, and #status=. To add the render helpers
92
+ # you're used to having in a normal controller, you can do the following:
93
+ #
94
+ # class HelloController < ActionController::Metal
95
+ # include AbstractController::Rendering
96
+ # include ActionView::Layouts
97
+ # append_view_path "#{Rails.root}/app/views"
98
+ #
99
+ # def index
100
+ # render "hello/index"
101
+ # end
102
+ # end
103
+ #
104
+ # ## Redirection Helpers
105
+ #
106
+ # To add redirection helpers to your metal controller, do the following:
107
+ #
108
+ # class HelloController < ActionController::Metal
109
+ # include ActionController::Redirecting
110
+ # include Rails.application.routes.url_helpers
111
+ #
112
+ # def index
113
+ # redirect_to root_url
114
+ # end
115
+ # end
116
+ #
117
+ # ## Other Helpers
118
+ #
119
+ # You can refer to the modules included in ActionController::Base to see other
120
+ # features you can bring into your metal controller.
121
+ class Metal < AbstractController::Base
122
+ abstract!
123
+
124
+ # Returns the last part of the controller's name, underscored, without the
125
+ # ending `Controller`. For instance, `PostsController` returns `posts`.
126
+ # Namespaces are left out, so `Admin::PostsController` returns `posts` as well.
127
+ #
128
+ # #### Returns
129
+ # * `string`
130
+ def self.controller_name
131
+ @controller_name ||= (name.demodulize.delete_suffix("Controller").underscore unless anonymous?)
132
+ end
133
+
134
+ def self.make_response!(request)
135
+ ActionDispatch::Response.new.tap do |res|
136
+ res.request = request
137
+ end
138
+ end
139
+
140
+ def self.action_encoding_template(action) # :nodoc:
141
+ false
142
+ end
143
+
144
+ class << self
145
+ private
146
+ def inherited(subclass)
147
+ super
148
+ subclass.middleware_stack = middleware_stack.dup
149
+ subclass.class_eval do
150
+ @controller_name = nil
151
+ end
152
+ end
153
+ end
154
+
155
+ # Delegates to the class's ::controller_name.
156
+ def controller_name
157
+ self.class.controller_name
158
+ end
159
+
160
+ ##
161
+ # :attr_reader: request
162
+ #
163
+ # The ActionDispatch::Request instance for the current request.
164
+ attr_internal :request
165
+
166
+ ##
167
+ # :attr_reader: response
168
+ #
169
+ # The ActionDispatch::Response instance for the current response.
170
+ attr_internal_reader :response
171
+
172
+ ##
173
+ # The ActionDispatch::Request::Session instance for the current request.
174
+ # See further details in the
175
+ # [Active Controller Session guide](https://guides.rubyonrails.org/action_controller_overview.html#session).
176
+ delegate :session, to: "@_request"
177
+
178
+ ##
179
+ # Delegates to ActionDispatch::Response#headers.
180
+ delegate :headers, to: "@_response"
181
+
182
+ ##
183
+ # Delegates to ActionDispatch::Response#status=
184
+ delegate :status=, to: "@_response"
185
+
186
+ ##
187
+ # Delegates to ActionDispatch::Response#location=
188
+ delegate :location=, to: "@_response"
189
+
190
+ ##
191
+ # Delegates to ActionDispatch::Response#content_type=
192
+ delegate :content_type=, to: "@_response"
193
+
194
+ ##
195
+ # Delegates to ActionDispatch::Response#status
196
+ delegate :status, to: "@_response"
197
+
198
+ ##
199
+ # Delegates to ActionDispatch::Response#location
200
+ delegate :location, to: "@_response"
201
+
202
+ ##
203
+ # Delegates to ActionDispatch::Response#content_type
204
+ delegate :content_type, to: "@_response"
205
+
206
+ ##
207
+ # Delegates to ActionDispatch::Response#media_type
208
+ delegate :media_type, to: "@_response"
209
+
210
+ def initialize
211
+ @_request = nil
212
+ @_response = nil
213
+ @_response_body = nil
214
+ @_routes = nil
215
+ @_params = nil
216
+ super
217
+ end
218
+
219
+ def params
220
+ @_params ||= request.parameters
221
+ end
222
+
223
+ def params=(val)
224
+ @_params = val
225
+ end
226
+
227
+ alias :response_code :status # :nodoc:
228
+
229
+ # Basic `url_for` that can be overridden for more robust functionality.
230
+ def url_for(string)
231
+ string
232
+ end
233
+
234
+ def response_body=(body)
235
+ if body
236
+ body = [body] if body.is_a?(String)
237
+ response.body = body
238
+ super
239
+ else
240
+ response.reset_body!
241
+ end
242
+ end
243
+
244
+ # Tests if render or redirect has already happened.
245
+ def performed?
246
+ response_body || response.committed?
247
+ end
248
+
249
+ def dispatch(name, request, response) # :nodoc:
250
+ set_request!(request)
251
+ set_response!(response)
252
+ process(name)
253
+ request.commit_flash
254
+ to_a
255
+ end
256
+
257
+ def set_response!(response) # :nodoc:
258
+ if @_response
259
+ _, _, body = @_response
260
+ body.close if body.respond_to?(:close)
261
+ end
262
+
263
+ @_response = response
264
+ end
265
+
266
+ # Assign the response and mark it as committed. No further processing will
267
+ # occur.
268
+ def response=(response)
269
+ set_response!(response)
270
+
271
+ # Force `performed?` to return true:
272
+ @_response_body = true
273
+ end
274
+
275
+ def set_request!(request) # :nodoc:
276
+ @_request = request
277
+ @_request.controller_instance = self
278
+ end
279
+
280
+ def to_a # :nodoc:
281
+ response.to_a
282
+ end
283
+
284
+ def reset_session
285
+ @_request.reset_session
286
+ end
287
+
288
+ class_attribute :middleware_stack, default: ActionController::MiddlewareStack.new
289
+
290
+ class << self
291
+ # Pushes the given Rack middleware and its arguments to the bottom of the
292
+ # middleware stack.
293
+ def use(...)
294
+ middleware_stack.use(...)
295
+ end
296
+ end
297
+
298
+ # The middleware stack used by this controller.
299
+ #
300
+ # By default uses a variation of ActionDispatch::MiddlewareStack which allows
301
+ # for the following syntax:
302
+ #
303
+ # class PostsController < ApplicationController
304
+ # use AuthenticationMiddleware, except: [:index, :show]
305
+ # end
306
+ #
307
+ # Read more about [Rails middleware stack]
308
+ # (https://guides.rubyonrails.org/rails_on_rack.html#action-dispatcher-middleware-stack)
309
+ # in the guides.
310
+ def self.middleware
311
+ middleware_stack
312
+ end
313
+
314
+ # Returns a Rack endpoint for the given action name.
315
+ def self.action(name)
316
+ app = lambda { |env|
317
+ req = ActionDispatch::Request.new(env)
318
+ res = make_response! req
319
+ new.dispatch(name, req, res)
320
+ }
321
+
322
+ if middleware_stack.any?
323
+ middleware_stack.build(name, app)
324
+ else
325
+ app
326
+ end
327
+ end
328
+
329
+ # Direct dispatch to the controller. Instantiates the controller, then executes
330
+ # the action named `name`.
331
+ def self.dispatch(name, req, res)
332
+ if middleware_stack.any?
333
+ middleware_stack.build(name) { |env| new.dispatch(name, req, res) }.call req.env
334
+ else
335
+ new.dispatch(name, req, res)
336
+ end
337
+ end
338
+ end
339
+ end
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :markup: markdown
4
+
5
+ require "rails"
6
+ require "action_controller"
7
+ require "action_dispatch/railtie"
8
+ require "abstract_controller/railties/routes_helpers"
9
+ require "action_controller/railties/helpers"
10
+ require "action_view/railtie"
11
+
12
+ module ActionController
13
+ class Railtie < Rails::Railtie # :nodoc:
14
+ config.action_controller = ActiveSupport::OrderedOptions.new
15
+ config.action_controller.raise_on_open_redirects = false
16
+ config.action_controller.log_query_tags_around_actions = true
17
+ config.action_controller.wrap_parameters_by_default = false
18
+
19
+ config.eager_load_namespaces << AbstractController
20
+ config.eager_load_namespaces << ActionController
21
+
22
+ initializer "action_controller.deprecator", before: :load_environment_config do |app|
23
+ app.deprecators[:action_controller] = ActionController.deprecator
24
+ end
25
+
26
+ initializer "action_controller.assets_config", group: :all do |app|
27
+ app.config.action_controller.assets_dir ||= app.config.paths["public"].first
28
+ end
29
+
30
+ initializer "action_controller.set_helpers_path" do |app|
31
+ ActionController::Helpers.helpers_path = app.helpers_paths
32
+ end
33
+
34
+ initializer "action_controller.parameters_config" do |app|
35
+ options = app.config.action_controller
36
+
37
+ ActiveSupport.on_load(:action_controller, run_once: true) do
38
+ ActionController::Parameters.permit_all_parameters = options.permit_all_parameters || false
39
+ if app.config.action_controller[:always_permitted_parameters]
40
+ ActionController::Parameters.always_permitted_parameters =
41
+ app.config.action_controller.always_permitted_parameters
42
+ end
43
+
44
+ action_on_unpermitted_parameters = options.action_on_unpermitted_parameters
45
+
46
+ if action_on_unpermitted_parameters.nil?
47
+ action_on_unpermitted_parameters = Rails.env.local? ? :log : false
48
+ end
49
+
50
+ ActionController::Parameters.action_on_unpermitted_parameters = action_on_unpermitted_parameters
51
+
52
+ unless options.allow_deprecated_parameters_hash_equality.nil?
53
+ ActionController::Parameters.allow_deprecated_parameters_hash_equality =
54
+ options.allow_deprecated_parameters_hash_equality
55
+ end
56
+ end
57
+ end
58
+
59
+ initializer "action_controller.set_configs" do |app|
60
+ paths = app.config.paths
61
+ options = app.config.action_controller
62
+
63
+ options.logger ||= Rails.logger
64
+ options.cache_store ||= Rails.cache
65
+
66
+ options.javascripts_dir ||= paths["public/javascripts"].first
67
+ options.stylesheets_dir ||= paths["public/stylesheets"].first
68
+
69
+ # Ensure readers methods get compiled.
70
+ options.asset_host ||= app.config.asset_host
71
+ options.relative_url_root ||= app.config.relative_url_root
72
+
73
+ ActiveSupport.on_load(:action_controller) do
74
+ include app.routes.mounted_helpers
75
+ extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
76
+ extend ::ActionController::Railties::Helpers
77
+
78
+ wrap_parameters format: [:json] if options.wrap_parameters_by_default && respond_to?(:wrap_parameters)
79
+
80
+ # Configs used in other initializers
81
+ filtered_options = options.except(
82
+ :default_protect_from_forgery,
83
+ :log_query_tags_around_actions,
84
+ :permit_all_parameters,
85
+ :action_on_unpermitted_parameters,
86
+ :always_permitted_parameters,
87
+ :wrap_parameters_by_default,
88
+ :allow_deprecated_parameters_hash_equality
89
+ )
90
+
91
+ filtered_options.each do |k, v|
92
+ k = "#{k}="
93
+ if respond_to?(k)
94
+ send(k, v)
95
+ elsif !Base.respond_to?(k)
96
+ raise "Invalid option key: #{k}"
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ initializer "action_controller.compile_config_methods" do
103
+ ActiveSupport.on_load(:action_controller) do
104
+ config.compile_methods! if config.respond_to?(:compile_methods!)
105
+ end
106
+ end
107
+
108
+ initializer "action_controller.request_forgery_protection" do |app|
109
+ ActiveSupport.on_load(:action_controller_base) do
110
+ if app.config.action_controller.default_protect_from_forgery
111
+ protect_from_forgery with: :exception
112
+ end
113
+ end
114
+ end
115
+
116
+ initializer "action_controller.query_log_tags" do |app|
117
+ query_logs_tags_enabled = app.config.respond_to?(:active_record) &&
118
+ app.config.active_record.query_log_tags_enabled &&
119
+ app.config.action_controller.log_query_tags_around_actions
120
+
121
+ if query_logs_tags_enabled
122
+ app.config.active_record.query_log_tags |= [:controller] unless app.config.active_record.query_log_tags.include?(:namespaced_controller)
123
+ app.config.active_record.query_log_tags |= [:action]
124
+
125
+ ActiveSupport.on_load(:active_record) do
126
+ ActiveRecord::QueryLogs.taggings = ActiveRecord::QueryLogs.taggings.merge(
127
+ controller: ->(context) { context[:controller]&.controller_name },
128
+ action: ->(context) { context[:controller]&.action_name },
129
+ namespaced_controller: ->(context) {
130
+ if context[:controller]
131
+ controller_class = context[:controller].class
132
+ # based on ActionController::Metal#controller_name, but does not demodulize
133
+ unless controller_class.anonymous?
134
+ controller_class.name.delete_suffix("Controller").underscore
135
+ end
136
+ end
137
+ }
138
+ )
139
+ end
140
+ end
141
+ end
142
+
143
+ initializer "action_controller.test_case" do |app|
144
+ ActiveSupport.on_load(:action_controller_test_case) do
145
+ ActionController::TestCase.executor_around_each_request = app.config.active_support.executor_around_test_case
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :markup: markdown
4
+
5
+ module ActionController
6
+ module Railties
7
+ module Helpers
8
+ def inherited(klass)
9
+ super
10
+ return unless klass.respond_to?(:helpers_path=)
11
+
12
+ if namespace = klass.module_parents.detect { |m| m.respond_to?(:railtie_helpers_paths) }
13
+ paths = namespace.railtie_helpers_paths
14
+ else
15
+ paths = ActionController::Helpers.helpers_path
16
+ end
17
+
18
+ klass.helpers_path = paths
19
+
20
+ if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
21
+ klass.helper :all
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end