actionpack 8.0.3 → 8.1.0.rc1

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +335 -158
  3. data/lib/abstract_controller/asset_paths.rb +4 -2
  4. data/lib/abstract_controller/base.rb +12 -3
  5. data/lib/abstract_controller/caching.rb +6 -3
  6. data/lib/abstract_controller/logger.rb +2 -1
  7. data/lib/action_controller/api.rb +1 -0
  8. data/lib/action_controller/base.rb +2 -1
  9. data/lib/action_controller/caching.rb +1 -2
  10. data/lib/action_controller/form_builder.rb +1 -1
  11. data/lib/action_controller/log_subscriber.rb +18 -3
  12. data/lib/action_controller/metal/allow_browser.rb +1 -1
  13. data/lib/action_controller/metal/conditional_get.rb +25 -0
  14. data/lib/action_controller/metal/data_streaming.rb +1 -3
  15. data/lib/action_controller/metal/exceptions.rb +5 -0
  16. data/lib/action_controller/metal/flash.rb +1 -4
  17. data/lib/action_controller/metal/head.rb +3 -1
  18. data/lib/action_controller/metal/live.rb +9 -18
  19. data/lib/action_controller/metal/permissions_policy.rb +9 -0
  20. data/lib/action_controller/metal/rate_limiting.rb +30 -9
  21. data/lib/action_controller/metal/redirecting.rb +104 -9
  22. data/lib/action_controller/metal/renderers.rb +27 -6
  23. data/lib/action_controller/metal/rendering.rb +7 -1
  24. data/lib/action_controller/metal/request_forgery_protection.rb +18 -10
  25. data/lib/action_controller/metal/rescue.rb +9 -0
  26. data/lib/action_controller/railtie.rb +27 -8
  27. data/lib/action_controller/structured_event_subscriber.rb +107 -0
  28. data/lib/action_dispatch/http/cache.rb +111 -1
  29. data/lib/action_dispatch/http/filter_parameters.rb +5 -3
  30. data/lib/action_dispatch/http/mime_negotiation.rb +55 -1
  31. data/lib/action_dispatch/http/mime_types.rb +1 -0
  32. data/lib/action_dispatch/http/param_builder.rb +28 -27
  33. data/lib/action_dispatch/http/parameters.rb +3 -3
  34. data/lib/action_dispatch/http/permissions_policy.rb +4 -0
  35. data/lib/action_dispatch/http/query_parser.rb +12 -10
  36. data/lib/action_dispatch/http/request.rb +10 -5
  37. data/lib/action_dispatch/http/response.rb +16 -3
  38. data/lib/action_dispatch/http/url.rb +110 -14
  39. data/lib/action_dispatch/journey/gtg/simulator.rb +33 -12
  40. data/lib/action_dispatch/journey/gtg/transition_table.rb +33 -41
  41. data/lib/action_dispatch/journey/nodes/node.rb +2 -1
  42. data/lib/action_dispatch/journey/route.rb +45 -31
  43. data/lib/action_dispatch/journey/router/utils.rb +8 -14
  44. data/lib/action_dispatch/journey/router.rb +59 -81
  45. data/lib/action_dispatch/journey/routes.rb +7 -0
  46. data/lib/action_dispatch/journey/visitors.rb +55 -23
  47. data/lib/action_dispatch/journey/visualizer/fsm.js +4 -6
  48. data/lib/action_dispatch/log_subscriber.rb +7 -3
  49. data/lib/action_dispatch/middleware/cookies.rb +4 -2
  50. data/lib/action_dispatch/middleware/debug_exceptions.rb +7 -1
  51. data/lib/action_dispatch/middleware/debug_view.rb +11 -0
  52. data/lib/action_dispatch/middleware/exception_wrapper.rb +11 -5
  53. data/lib/action_dispatch/middleware/executor.rb +12 -2
  54. data/lib/action_dispatch/middleware/public_exceptions.rb +1 -5
  55. data/lib/action_dispatch/middleware/remote_ip.rb +9 -4
  56. data/lib/action_dispatch/middleware/session/cache_store.rb +17 -0
  57. data/lib/action_dispatch/middleware/templates/rescues/_copy_button.html.erb +1 -0
  58. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +3 -2
  59. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +9 -5
  60. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +1 -0
  61. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +1 -0
  62. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +4 -0
  63. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +3 -0
  64. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +50 -0
  65. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -0
  66. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -0
  67. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -0
  68. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -0
  69. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -0
  70. data/lib/action_dispatch/railtie.rb +14 -2
  71. data/lib/action_dispatch/routing/inspector.rb +79 -56
  72. data/lib/action_dispatch/routing/mapper.rb +323 -173
  73. data/lib/action_dispatch/routing/redirection.rb +10 -7
  74. data/lib/action_dispatch/routing/route_set.rb +2 -4
  75. data/lib/action_dispatch/structured_event_subscriber.rb +20 -0
  76. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +2 -2
  77. data/lib/action_dispatch/testing/assertions/response.rb +14 -0
  78. data/lib/action_dispatch/testing/assertions/routing.rb +11 -3
  79. data/lib/action_dispatch/testing/integration.rb +1 -1
  80. data/lib/action_dispatch.rb +8 -0
  81. data/lib/action_pack/gem_version.rb +3 -3
  82. metadata +13 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b131da258151267320d978699cdc9ed60f96060bbeeb5bfa85f8da0ab648497f
4
- data.tar.gz: 2300ba0391c2e63f5e0ab71060bec7ef3e149d32064e5eccfd1a1f46ecad2820
3
+ metadata.gz: c8381d10158212e4c059184fe5d92666b06c59d245fb71694323238d90eba282
4
+ data.tar.gz: 0dc561b01b220cee074c0278ce18630f60772998a20804314efff2531ae0c4fb
5
5
  SHA512:
6
- metadata.gz: 13ee7198d843341f8b97aa564b70385fd26ee5e3bdd2560e56cc20a16591d8502daa4befec55a81bc4783e5451648acf35dd67de6ca62cf0b41f5ae37cec9557
7
- data.tar.gz: 17972b2a557984ad9a96f3947135fe29dd6aae6dfd0a019204be60e0d82056ed390333bad574ae9ec8d762b24574f4aac8103e04d647fca3a75736763ecae9f6
6
+ metadata.gz: 901e992f68e437ee2b51ae434592ae48e1c1f90928d3274db316618abbd036ab5e019e03a94826ba6e9f1d7c84fbff1e8f3080e46a39eb5336c615f317bb1058
7
+ data.tar.gz: 56cf6df4674a40dfd5d1c5084ae3d65566d72f3db8e0b848217fceb2d3a5e0b488ac22f87fe457507d66346c330b9946b641117667ea7308854d0029a0e7ef8a
data/CHANGELOG.md CHANGED
@@ -1,285 +1,462 @@
1
- ## Rails 8.0.3 (September 22, 2025) ##
1
+ ## Rails 8.1.0.rc1 (October 15, 2025) ##
2
2
 
3
- * URL helpers for engines mounted at the application root handle `SCRIPT_NAME` correctly.
3
+ * Add link-local IP ranges to `ActionDispatch::RemoteIp` default proxies.
4
4
 
5
- Fixed an issue where `SCRIPT_NAME` is not applied to paths generated for routes in an engine
6
- mounted at "/".
5
+ Link-local addresses (`169.254.0.0/16` for IPv4 and `fe80::/10` for IPv6)
6
+ are now included in the default trusted proxy list, similar to private IP ranges.
7
7
 
8
- *Mike Dalessio*
8
+ *Adam Daniels*
9
9
 
10
- * Fix `Rails.application.reload_routes!` from clearing almost all routes.
10
+ * `remote_ip` will no longer ignore IPs in X-Forwarded-For headers if they
11
+ are accompanied by port information.
11
12
 
12
- When calling `Rails.application.reload_routes!` inside a middleware of
13
- a Rake task, it was possible under certain conditions that all routes would be cleared.
14
- If ran inside a middleware, this would result in getting a 404 on most page you visit.
15
- This issue was only happening in development.
13
+ *Duncan Brown*, *Prevenios Marinos*, *Masafumi Koba*, *Adam Daniels*
16
14
 
17
- *Edouard Chin*
15
+ * Add `action_dispatch.verbose_redirect_logs` setting that logs where redirects were called from.
16
+
17
+ Similar to `active_record.verbose_query_logs` and `active_job.verbose_enqueue_logs`, this adds a line in your logs that shows where a redirect was called from.
18
18
 
19
- * Address `rack 3.2` deprecations warnings.
19
+ Example:
20
20
 
21
21
  ```
22
- warning: Status code :unprocessable_entity is deprecated and will be removed in a future version of Rack.
23
- Please use :unprocessable_content instead.
22
+ Redirected to http://localhost:3000/posts/1
23
+ app/controllers/posts_controller.rb:32:in `block (2 levels) in create'
24
24
  ```
25
25
 
26
- Rails API will transparently convert one into the other for the foreseeable future.
26
+ *Dennis Paagman*
27
27
 
28
- *Earlopain*, *Jean Boussier*
28
+ * Add engine route filtering and better formatting in `bin/rails routes`.
29
29
 
30
- * Support hash-source in Content Security Policy.
30
+ Allow engine routes to be filterable in the routing inspector, and
31
+ improve formatting of engine routing output.
31
32
 
32
- *madogiwa*
33
+ Before:
34
+ ```
35
+ > bin/rails routes -e engine_only
36
+ No routes were found for this grep pattern.
37
+ For more information about routes, see the Rails guide: https://guides.rubyonrails.org/routing.html.
38
+ ```
33
39
 
34
- * Always return empty body for HEAD requests in `PublicExceptions` and
35
- `DebugExceptions`.
40
+ After:
41
+ ```
42
+ > bin/rails routes -e engine_only
43
+ Routes for application:
44
+ No routes were found for this grep pattern.
45
+ For more information about routes, see the Rails guide: https://guides.rubyonrails.org/routing.html.
46
+
47
+ Routes for Test::Engine:
48
+ Prefix Verb URI Pattern Controller#Action
49
+ engine GET /engine_only(.:format) a#b
50
+ ```
36
51
 
37
- This is required by `Rack::Lint` (per RFC9110).
52
+ *Dennis Paagman*, *Gannon McGibbon*
38
53
 
39
- *Hartley McGuire*
54
+ * Add structured events for Action Pack and Action Dispatch:
55
+ - `action_dispatch.redirect`
56
+ - `action_controller.request_started`
57
+ - `action_controller.request_completed`
58
+ - `action_controller.callback_halted`
59
+ - `action_controller.rescue_from_handled`
60
+ - `action_controller.file_sent`
61
+ - `action_controller.redirected`
62
+ - `action_controller.data_sent`
63
+ - `action_controller.unpermitted_parameters`
64
+ - `action_controller.fragment_cache`
40
65
 
66
+ *Adrianna Chang*
41
67
 
42
- ## Rails 8.0.2.1 (August 13, 2025) ##
68
+ * URL helpers for engines mounted at the application root handle `SCRIPT_NAME` correctly.
43
69
 
44
- * No changes.
70
+ Fixed an issue where `SCRIPT_NAME` is not applied to paths generated for routes in an engine
71
+ mounted at "/".
45
72
 
46
- ## Rails 8.0.2 (March 12, 2025) ##
73
+ *Mike Dalessio*
47
74
 
48
- * Improve `with_routing` test helper to not rebuild the middleware stack.
75
+ * Update `ActionController::Metal::RateLimiting` to support passing method names to `:by` and `:with`
49
76
 
50
- Otherwise some middleware configuration could be lost.
77
+ ```ruby
78
+ class SignupsController < ApplicationController
79
+ rate_limit to: 10, within: 1.minute, with: :redirect_with_flash
51
80
 
52
- *Édouard Chin*
81
+ private
82
+ def redirect_with_flash
83
+ redirect_to root_url, alert: "Too many requests!"
84
+ end
85
+ end
86
+ ```
53
87
 
54
- * Add resource name to the `ArgumentError` that's raised when invalid `:only` or `:except` options are given to `#resource` or `#resources`
88
+ *Sean Doyle*
55
89
 
56
- This makes it easier to locate the source of the problem, especially for routes drawn by gems.
90
+ * Optimize `ActionDispatch::Http::URL.build_host_url` when protocol is included in host.
91
+
92
+ When using URL helpers with a host that includes the protocol (e.g., `{ host: "https://example.com" }`),
93
+ skip unnecessary protocol normalization and string duplication since the extracted protocol is already
94
+ in the correct format. This eliminates 2 string allocations per URL generation and provides a ~10%
95
+ performance improvement for this case.
96
+
97
+ *Joshua Young*, *Hartley McGuire*
98
+
99
+ * Allow `action_controller.logger` to be disabled by setting it to `nil` or `false` instead of always defaulting to `Rails.logger`.
100
+
101
+ *Roberto Miranda*
102
+
103
+ ## Rails 8.1.0.beta1 (September 04, 2025) ##
104
+
105
+ * Remove deprecated support to a route to multiple paths.
106
+
107
+ *Rafael Mendonça França*
108
+
109
+ * Remove deprecated support for using semicolons as a query string separator.
57
110
 
58
111
  Before:
59
- ```
60
- :only and :except must include only [:index, :create, :new, :show, :update, :destroy, :edit], but also included [:foo, :bar]
112
+
113
+ ```ruby
114
+ ActionDispatch::QueryParser.each_pair("foo=bar;baz=quux").to_a
115
+ # => [["foo", "bar"], ["baz", "quux"]]
61
116
  ```
62
117
 
63
118
  After:
64
- ```
65
- Route `resources :products` - :only and :except must include only [:index, :create, :new, :show, :update, :destroy, :edit], but also included [:foo, :bar]
119
+
120
+ ```ruby
121
+ ActionDispatch::QueryParser.each_pair("foo=bar;baz=quux").to_a
122
+ # => [["foo", "bar;baz=quux"]]
66
123
  ```
67
124
 
68
- *Jeremy Green*
125
+ *Rafael Mendonça França*
69
126
 
70
- * Fix `url_for` to handle `:path_params` gracefully when it's not a `Hash`.
127
+ * Remove deprecated support to skipping over leading brackets in parameter names in the parameter parser.
71
128
 
72
- Prevents various security scanners from causing exceptions.
129
+ Before:
73
130
 
74
- *Martin Emde*
131
+ ```ruby
132
+ ActionDispatch::ParamBuilder.from_query_string("[foo]=bar") # => { "foo" => "bar" }
133
+ ActionDispatch::ParamBuilder.from_query_string("[foo][bar]=baz") # => { "foo" => { "bar" => "baz" } }
134
+ ```
75
135
 
76
- * Fix `ActionDispatch::Executor` to unwrap exceptions like other error reporting middlewares.
136
+ After:
77
137
 
78
- *Jean Boussier*
138
+ ```ruby
139
+ ActionDispatch::ParamBuilder.from_query_string("[foo]=bar") # => { "[foo]" => "bar" }
140
+ ActionDispatch::ParamBuilder.from_query_string("[foo][bar]=baz") # => { "[foo]" => { "bar" => "baz" } }
141
+ ```
79
142
 
143
+ *Rafael Mendonça França*
80
144
 
81
- ## Rails 8.0.1 (December 13, 2024) ##
145
+ * Deprecate `Rails.application.config.action_dispatch.ignore_leading_brackets`.
82
146
 
83
- * Add `ActionDispatch::Request::Session#store` method to conform Rack spec.
147
+ *Rafael Mendonça França*
84
148
 
85
- *Yaroslav*
149
+ * Raise `ActionController::TooManyRequests` error from `ActionController::RateLimiting`
86
150
 
151
+ Requests that exceed the rate limit raise an `ActionController::TooManyRequests` error.
152
+ By default, Action Dispatch rescues the error and responds with a `429 Too Many Requests` status.
87
153
 
88
- ## Rails 8.0.0.1 (December 10, 2024) ##
154
+ *Sean Doyle*
89
155
 
90
- * Add validation to content security policies to disallow spaces and semicolons.
91
- Developers should use multiple arguments, and different directive methods instead.
156
+ * Add .md/.markdown as Markdown extensions and add a default `markdown:` renderer:
92
157
 
93
- [CVE-2024-54133]
158
+ ```ruby
159
+ class Page
160
+ def to_markdown
161
+ body
162
+ end
163
+ end
94
164
 
95
- *Gannon McGibbon*
165
+ class PagesController < ActionController::Base
166
+ def show
167
+ @page = Page.find(params[:id])
96
168
 
169
+ respond_to do |format|
170
+ format.html
171
+ format.md { render markdown: @page }
172
+ end
173
+ end
174
+ end
175
+ ```
97
176
 
98
- ## Rails 8.0.0 (November 07, 2024) ##
177
+ *DHH*
99
178
 
100
- * No changes.
179
+ * Add headers to engine routes inspection command
101
180
 
181
+ *Petrik de Heus*
102
182
 
103
- ## Rails 8.0.0.rc2 (October 30, 2024) ##
183
+ * Add "Copy as text" button to error pages
104
184
 
105
- * Fix routes with `::` in the path.
185
+ *Mikkel Malmberg*
106
186
 
107
- *Rafael Mendonça França*
187
+ * Add `scope:` option to `rate_limit` method.
108
188
 
109
- * Maintain Rack 2 parameter parsing behaviour.
189
+ Previously, it was not possible to share a rate limit count between several controllers, since the count was by
190
+ default separate for each controller.
110
191
 
111
- *Matthew Draper*
192
+ Now, the `scope:` option solves this problem.
112
193
 
194
+ ```ruby
195
+ class APIController < ActionController::API
196
+ rate_limit to: 2, within: 2.seconds, scope: "api"
197
+ end
113
198
 
114
- ## Rails 8.0.0.rc1 (October 19, 2024) ##
199
+ class API::PostsController < APIController
200
+ # ...
201
+ end
115
202
 
116
- * Remove `Rails.application.config.action_controller.allow_deprecated_parameters_hash_equality`.
203
+ class API::UsersController < APIController
204
+ # ...
205
+ end
206
+ ```
117
207
 
118
- *Rafael Mendonça França*
208
+ *ArthurPV*, *Kamil Hanus*
119
209
 
120
- * Improve `ActionController::TestCase` to expose a binary encoded `request.body`.
210
+ * Add support for `rack.response_finished` callbacks in ActionDispatch::Executor.
121
211
 
122
- The rack spec clearly states:
212
+ The executor middleware now supports deferring completion callbacks to later
213
+ in the request lifecycle by utilizing Rack's `rack.response_finished` mechanism,
214
+ when available. This enables applications to define `rack.response_finished` callbacks
215
+ that may rely on state that would be cleaned up by the executor's completion callbacks.
123
216
 
124
- > The input stream is an IO-like object which contains the raw HTTP POST data.
125
- > When applicable, its external encoding must be “ASCII-8BIT” and it must be opened in binary mode.
217
+ *Adrianna Chang*, *Hartley McGuire*
126
218
 
127
- Until now its encoding was generally UTF-8, which doesn't accurately reflect production
128
- behavior.
219
+ * Produce a log when `rescue_from` is invoked.
129
220
 
130
- *Jean Boussier*
221
+ *Steven Webb*, *Jean Boussier*
131
222
 
132
- * Update `ActionController::AllowBrowser` to support passing method names to `:block`
223
+ * Allow hosts redirects from `hosts` Rails configuration
133
224
 
134
225
  ```ruby
135
- class ApplicationController < ActionController::Base
136
- allow_browser versions: :modern, block: :handle_outdated_browser
137
-
138
- private
139
- def handle_outdated_browser
140
- render file: Rails.root.join("public/custom-error.html"), status: :not_acceptable
141
- end
142
- end
226
+ config.action_controller.allowed_redirect_hosts << "example.com"
143
227
  ```
144
228
 
145
- *Sean Doyle*
229
+ *Kevin Robatel*
146
230
 
147
- * Raise an `ArgumentError` when invalid `:only` or `:except` options are passed into `#resource` and `#resources`.
231
+ * `rate_limit.action_controller` notification has additional payload
148
232
 
149
- *Joshua Young*
233
+ additional values: count, to, within, by, name, cache_key
150
234
 
151
- ## Rails 8.0.0.beta1 (September 26, 2024) ##
235
+ *Jonathan Rochkind*
152
236
 
153
- * Fix non-GET requests not updating cookies in `ActionController::TestCase`.
237
+ * Add JSON support to the built-in health controller.
154
238
 
155
- *Jon Moss*, *Hartley McGuire*
239
+ The health controller now responds to JSON requests with a structured response
240
+ containing status and timestamp information. This makes it easier for monitoring
241
+ tools and load balancers to consume health check data programmatically.
156
242
 
157
- * Update `ActionController::Live` to use a thread-pool to reuse threads across requests.
243
+ ```ruby
244
+ # /up.json
245
+ {
246
+ "status": "up",
247
+ "timestamp": "2025-09-19T12:00:00Z"
248
+ }
249
+ ```
158
250
 
159
- *Adam Renberg Tamm*
251
+ *Francesco Loreti*, *Juan Vásquez*
160
252
 
161
- * Introduce safer, more explicit params handling method with `params#expect` such that
162
- `params.expect(table: [ :attr ])` replaces `params.require(:table).permit(:attr)`
253
+ * Allow to open source file with a crash from the browser.
163
254
 
164
- Ensures params are filtered with consideration for the expected
165
- types of values, improving handling of params and avoiding ignorable
166
- errors caused by params tampering.
255
+ *Igor Kasyanchuk*
167
256
 
168
- ```ruby
169
- # If the url is altered to ?person=hacked
170
- # Before
171
- params.require(:person).permit(:name, :age, pets: [:name])
172
- # raises NoMethodError, causing a 500 and potential error reporting
257
+ * Always check query string keys for valid encoding just like values are checked.
173
258
 
174
- # After
175
- params.expect(person: [ :name, :age, pets: [[:name]] ])
176
- # raises ActionController::ParameterMissing, correctly returning a 400 error
177
- ```
259
+ *Casper Smits*
178
260
 
179
- You may also notice the new double array `[[:name]]`. In order to
180
- declare when a param is expected to be an array of parameter hashes,
181
- this new double array syntax is used to explicitly declare an array.
182
- `expect` requires you to declare expected arrays in this way, and will
183
- ignore arrays that are passed when, for example, `pet: [:name]` is used.
261
+ * Always return empty body for HEAD requests in `PublicExceptions` and
262
+ `DebugExceptions`.
184
263
 
185
- In order to preserve compatibility, `permit` does not adopt the new
186
- double array syntax and is therefore more permissive about unexpected
187
- types. Using `expect` everywhere is recommended.
264
+ This is required by `Rack::Lint` (per RFC9110).
188
265
 
189
- We suggest replacing `params.require(:person).permit(:name, :age)`
190
- with the direct replacement `params.expect(person: [:name, :age])`
191
- to prevent external users from manipulating params to trigger 500
192
- errors. A 400 error will be returned instead, using public/400.html
266
+ *Hartley McGuire*
193
267
 
194
- Usage of `params.require(:id)` should likewise be replaced with
195
- `params.expect(:id)` which is designed to ensure that `params[:id]`
196
- is a scalar and not an array or hash, also requiring the param.
268
+ * Add comprehensive support for HTTP Cache-Control request directives according to RFC 9111.
269
+
270
+ Provides a `request.cache_control_directives` object that gives access to request cache directives:
197
271
 
198
272
  ```ruby
199
- # Before
200
- User.find(params.require(:id)) # allows an array, altering behavior
273
+ # Boolean directives
274
+ request.cache_control_directives.only_if_cached? # => true/false
275
+ request.cache_control_directives.no_cache? # => true/false
276
+ request.cache_control_directives.no_store? # => true/false
277
+ request.cache_control_directives.no_transform? # => true/false
278
+
279
+ # Value directives
280
+ request.cache_control_directives.max_age # => integer or nil
281
+ request.cache_control_directives.max_stale # => integer or nil (or true for valueless max-stale)
282
+ request.cache_control_directives.min_fresh # => integer or nil
283
+ request.cache_control_directives.stale_if_error # => integer or nil
284
+
285
+ # Special helpers for max-stale
286
+ request.cache_control_directives.max_stale? # => true if max-stale present (with or without value)
287
+ request.cache_control_directives.max_stale_unlimited? # => true only for valueless max-stale
288
+ ```
201
289
 
202
- # After
203
- User.find(params.expect(:id)) # expect only returns non-blank permitted scalars (excludes Hash, Array, nil, "", etc)
290
+ Example usage:
291
+
292
+ ```ruby
293
+ def show
294
+ if request.cache_control_directives.only_if_cached?
295
+ @article = Article.find_cached(params[:id])
296
+ return head(:gateway_timeout) if @article.nil?
297
+ else
298
+ @article = Article.find(params[:id])
299
+ end
300
+
301
+ render :show
302
+ end
204
303
  ```
205
304
 
206
- *Martin Emde*
305
+ *egg528*
207
306
 
208
- * System Testing: Disable Chrome's search engine choice by default in system tests.
307
+ * Add assert_in_body/assert_not_in_body as the simplest way to check if a piece of text is in the response body.
209
308
 
210
- *glaszig*
309
+ *DHH*
211
310
 
212
- * Fix `Request#raw_post` raising `NoMethodError` when `rack.input` is `nil`.
311
+ * Include cookie name when calculating maximum allowed size.
213
312
 
214
313
  *Hartley McGuire*
215
314
 
216
- * Remove `racc` dependency by manually writing `ActionDispatch::Journey::Scanner`.
315
+ * Implement `must-understand` directive according to RFC 9111.
217
316
 
218
- *Gannon McGibbon*
317
+ The `must-understand` directive indicates that a cache must understand the semantics of the response status code, or discard the response. This directive is enforced to be used only with `no-store` to ensure proper cache behavior.
219
318
 
220
- * Speed up `ActionDispatch::Routing::Mapper::Scope#[]` by merging frame hashes.
319
+ ```ruby
320
+ class ArticlesController < ApplicationController
321
+ def show
322
+ @article = Article.find(params[:id])
323
+
324
+ if @article.special_format?
325
+ must_understand
326
+ render status: 203 # Non-Authoritative Information
327
+ else
328
+ fresh_when @article
329
+ end
330
+ end
331
+ end
332
+ ```
221
333
 
222
- *Gannon McGibbon*
334
+ *heka1024*
223
335
 
224
- * Allow bots to ignore `allow_browser`.
336
+ * The JSON renderer doesn't escape HTML entities or Unicode line separators anymore.
225
337
 
226
- *Matthew Nguyen*
338
+ Using `render json:` will no longer escape `<`, `>`, `&`, `U+2028` and `U+2029` characters that can cause errors
339
+ when the resulting JSON is embedded in JavaScript, or vulnerabilities when the resulting JSON is embedded in HTML.
227
340
 
228
- * Deprecate drawing routes with multiple paths to make routing faster.
229
- You may use `with_options` or a loop to make drawing multiple paths easier.
341
+ Since the renderer is used to return a JSON document as `application/json`, it's typically not necessary to escape
342
+ those characters, and it improves performance.
230
343
 
231
- ```ruby
232
- # Before
233
- get "/users", "/other_path", to: "users#index"
344
+ Escaping will still occur when the `:callback` option is set, since the JSON is used as JavaScript code in this
345
+ situation (JSONP).
234
346
 
235
- # After
236
- get "/users", to: "users#index"
237
- get "/other_path", to: "users#index"
347
+ You can use the `:escape` option or set `config.action_controller.escape_json_responses` to `true` to restore the
348
+ escaping behavior.
349
+
350
+ ```ruby
351
+ class PostsController < ApplicationController
352
+ def index
353
+ render json: Post.last(30), escape: true
354
+ end
355
+ end
238
356
  ```
239
357
 
240
- *Gannon McGibbon*
358
+ *Étienne Barrié*, *Jean Boussier*
241
359
 
242
- * Make `http_cache_forever` use `immutable: true`
360
+ * Load lazy route sets before inserting test routes
243
361
 
244
- *Nate Matykiewicz*
362
+ Without loading lazy route sets early, we miss `after_routes_loaded` callbacks, or risk
363
+ invoking them with the test routes instead of the real ones if another load is triggered by an engine.
245
364
 
246
- * Add `config.action_dispatch.strict_freshness`.
365
+ *Gannon McGibbon*
247
366
 
248
- When set to `true`, the `ETag` header takes precedence over the `Last-Modified` header when both are present,
249
- as specified by RFC 7232, Section 6.
367
+ * Raise `AbstractController::DoubleRenderError` if `head` is called after rendering.
250
368
 
251
- Defaults to `false` to maintain compatibility with previous versions of Rails, but is enabled as part of
252
- Rails 8.0 defaults.
369
+ After this change, invoking `head` will lead to an error if response body is already set:
253
370
 
254
- *heka1024*
371
+ ```ruby
372
+ class PostController < ApplicationController
373
+ def index
374
+ render locals: {}
375
+ head :ok
376
+ end
377
+ end
378
+ ```
379
+
380
+ *Iaroslav Kurbatov*
255
381
 
256
- * Support `immutable` directive in Cache-Control
382
+ * The Cookie Serializer can now serialize an Active Support SafeBuffer when using message pack.
383
+
384
+ Such code would previously produce an error if an application was using messagepack as its cookie serializer.
257
385
 
258
386
  ```ruby
259
- expires_in 1.minute, public: true, immutable: true
260
- # Cache-Control: public, max-age=60, immutable
387
+ class PostController < ApplicationController
388
+ def index
389
+ flash.notice = t(:hello_html) # This would try to serialize a SafeBuffer, which was not possible.
390
+ end
391
+ end
261
392
  ```
262
393
 
263
- *heka1024*
394
+ *Edouard Chin*
264
395
 
265
- * Add `:wasm_unsafe_eval` mapping for `content_security_policy`
396
+ * Fix `Rails.application.reload_routes!` from clearing almost all routes.
266
397
 
267
- ```ruby
268
- # Before
269
- policy.script_src "'wasm-unsafe-eval'"
398
+ When calling `Rails.application.reload_routes!` inside a middleware of
399
+ a Rake task, it was possible under certain conditions that all routes would be cleared.
400
+ If ran inside a middleware, this would result in getting a 404 on most page you visit.
401
+ This issue was only happening in development.
270
402
 
271
- # After
272
- policy.script_src :wasm_unsafe_eval
403
+ *Edouard Chin*
404
+
405
+ * Add resource name to the `ArgumentError` that's raised when invalid `:only` or `:except` options are given to `#resource` or `#resources`
406
+
407
+ This makes it easier to locate the source of the problem, especially for routes drawn by gems.
408
+
409
+ Before:
410
+ ```
411
+ :only and :except must include only [:index, :create, :new, :show, :update, :destroy, :edit], but also included [:foo, :bar]
412
+ ```
413
+
414
+ After:
273
415
  ```
416
+ Route `resources :products` - :only and :except must include only [:index, :create, :new, :show, :update, :destroy, :edit], but also included [:foo, :bar]
417
+ ```
418
+
419
+ *Jeremy Green*
420
+
421
+ * A route pointing to a non-existing controller now returns a 500 instead of a 404.
422
+
423
+ A controller not existing isn't a routing error that should result
424
+ in a 404, but a programming error that should result in a 500 and
425
+ be reported.
426
+
427
+ Until recently, this was hard to untangle because of the support
428
+ for dynamic `:controller` segment in routes, but since this is
429
+ deprecated and will be removed in Rails 8.1, we can now easily
430
+ not consider missing controllers as routing errors.
431
+
432
+ *Jean Boussier*
433
+
434
+ * Add `check_collisions` option to `ActionDispatch::Session::CacheStore`.
435
+
436
+ Newly generated session ids use 128 bits of randomness, which is more than
437
+ enough to ensure collisions can't happen, but if you need to harden sessions
438
+ even more, you can enable this option to check in the session store that the id
439
+ is indeed free you can enable that option. This however incurs an extra write
440
+ on session creation.
441
+
442
+ *Shia*
443
+
444
+ * In ExceptionWrapper, match backtrace lines with built templates more often,
445
+ allowing improved highlighting of errors within do-end blocks in templates.
446
+ Fix for Ruby 3.4 to match new method labels in backtrace.
274
447
 
275
- *Joe Haig*
448
+ *Martin Emde*
276
449
 
277
- * Add `display_capture` and `keyboard_map` in `permissions_policy`
450
+ * Allow setting content type with a symbol of the Mime type.
278
451
 
279
- *Cyril Blaecke*
452
+ ```ruby
453
+ # Before
454
+ response.content_type = "text/html"
280
455
 
281
- * Add `connect` route helper.
456
+ # After
457
+ response.content_type = :html
458
+ ```
282
459
 
283
- *Samuel Williams*
460
+ *Petrik de Heus*
284
461
 
285
- Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/actionpack/CHANGELOG.md) for previous changes.
462
+ Please check [8-0-stable](https://github.com/rails/rails/blob/8-0-stable/actionpack/CHANGELOG.md) for previous changes.
@@ -7,8 +7,10 @@ module AbstractController
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  included do
10
- config_accessor :asset_host, :assets_dir, :javascripts_dir,
11
- :stylesheets_dir, :default_asset_host_protocol, :relative_url_root
10
+ singleton_class.delegate :asset_host, :asset_host=, :assets_dir, :assets_dir=, :javascripts_dir, :javascripts_dir=,
11
+ :stylesheets_dir, :stylesheets_dir=, :default_asset_host_protocol, :default_asset_host_protocol=, :relative_url_root, :relative_url_root=, to: :config
12
+ delegate :asset_host, :asset_host=, :assets_dir, :assets_dir=, :javascripts_dir, :javascripts_dir=,
13
+ :stylesheets_dir, :stylesheets_dir=, :default_asset_host_protocol, :default_asset_host_protocol=, :relative_url_root, :relative_url_root=, to: :config
12
14
  end
13
15
  end
14
16
  end