mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
40fc1651ad
While trying to fix #16433, we made the middleware deletions always happen at the end. While this works for the case of deleting the Rack::Runtime middleware, it makes operations like the following misbehave. ```ruby gem "bundler", "< 1.16" begin require "bundler/inline" rescue LoadError => e $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" raise e end gemfile(true) do source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem "rails", github: "rails/rails" end require "action_controller/railtie" class TestApp < Rails::Application config.root = __dir__ secrets.secret_key_base = "secret_key_base" config.logger = Logger.new($stdout) Rails.logger = config.logger middleware.insert_after ActionDispatch::Session::CookieStore, ::Rails::Rack::Logger, config.log_tags middleware.delete ::Rails::Rack::Logger end require "minitest/autorun" require "rack/test" class BugTest < Minitest::Test include Rack::Test::Methods def test_returns_success get "/" assert last_response.ok? end private def app Rails.application end end ``` In the case ☝️ the ::Rails::Rack::Logger would be deleted instead of moved, because the order of middleware stack building execution will be: ```ruby [:insert, ActionDispatch::Session::CookieStore, [::Rails::Rack::Logger]] [:delete, ::Rails::Rack::Logger, [config.log_tags]] ``` This is pretty surprising and hard to reason about behaviour, unless you go spelunking into the Rails configuration code. I have a few solutions in mind and all of them have their drawbacks. 1. Introduce a `Rails::Configuration::MiddlewareStackProxy#delete!` that delays the deleted operations. This will make `#delete` to be executed in order. The drawback here is backwards incompatible behavior and a new public method. 2. Just revert to the old operations. This won't allow people to delete the `Rack::Runtime` middleware. 3. Legitimize the middleware moving with the new `#move_after` and `#move_before` methods. This does not breaks any backwards compatibility, but includes 2 new methods to the middleware stack. I have implemented `3.` in this pull request. Happy holidays! 🎄 |
||
---|---|---|
.. | ||
kindle | ||
2_2_release_notes.md | ||
2_3_release_notes.md | ||
3_0_release_notes.md | ||
3_1_release_notes.md | ||
3_2_release_notes.md | ||
4_0_release_notes.md | ||
4_1_release_notes.md | ||
4_2_release_notes.md | ||
5_0_release_notes.md | ||
5_1_release_notes.md | ||
5_2_release_notes.md | ||
6_0_release_notes.md | ||
_license.html.erb | ||
_welcome.html.erb | ||
action_cable_overview.md | ||
action_controller_overview.md | ||
action_mailbox_basics.md | ||
action_mailer_basics.md | ||
action_text_overview.md | ||
action_view_overview.md | ||
active_job_basics.md | ||
active_model_basics.md | ||
active_record_basics.md | ||
active_record_callbacks.md | ||
active_record_migrations.md | ||
active_record_multiple_databases.md | ||
active_record_postgresql.md | ||
active_record_querying.md | ||
active_record_validations.md | ||
active_storage_overview.md | ||
active_support_core_extensions.md | ||
active_support_instrumentation.md | ||
api_app.md | ||
api_documentation_guidelines.md | ||
asset_pipeline.md | ||
association_basics.md | ||
autoloading_and_reloading_constants.md | ||
autoloading_and_reloading_constants_classic_mode.md | ||
caching_with_rails.md | ||
command_line.md | ||
configuring.md | ||
contributing_to_ruby_on_rails.md | ||
debugging_rails_applications.md | ||
development_dependencies_install.md | ||
documents.yaml | ||
engines.md | ||
form_helpers.md | ||
generators.md | ||
getting_started.md | ||
i18n.md | ||
index.html.erb | ||
initialization.md | ||
layout.html.erb | ||
layouts_and_rendering.md | ||
maintenance_policy.md | ||
plugins.md | ||
rails_application_templates.md | ||
rails_on_rack.md | ||
routing.md | ||
ruby_on_rails_guides_guidelines.md | ||
security.md | ||
testing.md | ||
threading_and_code_execution.md | ||
upgrading_ruby_on_rails.md | ||
working_with_javascript_in_rails.md |