diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /config/initializers/labkit_middleware.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'config/initializers/labkit_middleware.rb')
-rw-r--r-- | config/initializers/labkit_middleware.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/config/initializers/labkit_middleware.rb b/config/initializers/labkit_middleware.rb index ea4103f052f..748666b6cd7 100644 --- a/config/initializers/labkit_middleware.rb +++ b/config/initializers/labkit_middleware.rb @@ -1,3 +1,36 @@ # frozen_string_literal: true -Rails.application.config.middleware.use(Labkit::Middleware::Rack) +# partial backport of https://github.com/rails/rails/pull/38169 +# this is in order to be able to re-order rack middlewares. + +if ActionDispatch::MiddlewareStack.method_defined?(:move) + warn "`move` is now defined in in ActionDispatch itself: https://github.com/rails/rails/pull/38169, please remove this patch from #{__FILE__}" +else + module ActionDispatch + class MiddlewareStack + def move(target, source) + source_index = assert_index(source, :before) + source_middleware = middlewares.delete_at(source_index) + + target_index = assert_index(target, :before) + middlewares.insert(target_index, source_middleware) + end + end + end +end + +unless Rails::Configuration::MiddlewareStackProxy.method_defined?(:move) + module Rails + module Configuration + class MiddlewareStackProxy + def move(*args, &block) + @operations << ->(middleware) { middleware.send(__method__, *args, &block) } + end + ruby2_keywords(:move) if respond_to?(:ruby2_keywords, true) + end + end + end +end + +Rails.application.config.middleware.move(1, ActionDispatch::RequestId) +Rails.application.config.middleware.insert_after(ActionDispatch::RequestId, Labkit::Middleware::Rack) |