Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Expose MiddlewareStack#unshift to environment configuration #12479

Merged
merged 1 commit into from

4 participants

Ben Pickles Paul Nikitochkin Yves Senn José Valim
Ben Pickles

Although #6372 added #unshift to the middleware stack this is not exposed in the environment configuration files.

I wanted to be able to add basic auth to my app and ensure that it was the first middleware to be hit, although I could use #insert_before my stack differs between environments. This change ensures that the following is possible:

config.middleware.unshift Rack::Auth::Basic, 'Restricted Area' do |user, pwd|
  [user, pwd] == ['admin', 'admin']
end
Paul Nikitochkin

To complete this PR need to add Changelog entry.

Ben Pickles

Thanks, I updated the changelog.

Yves Senn
Owner

@josevalim I've seen you merged #6372 can you take a look?

José Valim josevalim merged commit 47ee9fe into from
José Valim
Owner

Thanks @benpickles / @senny / @pftg !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4 railties/CHANGELOG.md
View
@@ -1,3 +1,7 @@
+* Expose MiddlewareStack#unshift to environment configuration.
+
+ *Ben Pickles*
+
* Include `web-console` into newly generated applications' Gemfile.
*Genadi Samokovarov*
4 railties/lib/rails/configuration.rb
View
@@ -59,6 +59,10 @@ def delete(*args, &block)
@operations << [__method__, args, block]
end
+ def unshift(*args, &block)
+ @operations << [__method__, args, block]
+ end
+
def merge_into(other) #:nodoc:
@operations.each do |operation, args, block|
other.send(operation, *args, &block)
6 railties/test/application/middleware_test.rb
View
@@ -144,6 +144,12 @@ def app
assert_equal "Rack::Config", middleware.second
end
+ test 'unshift middleware' do
+ add_to_config 'config.middleware.unshift Rack::Config'
+ boot!
+ assert_equal 'Rack::Config', middleware.first
+ end
+
test "Rails.cache does not respond to middleware" do
add_to_config "config.cache_store = :memory_store"
boot!
Something went wrong with that request. Please try again.