1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Restore class-level middleware APIs for backwards compat, fixes #4821

This commit is contained in:
Mike Perham 2021-02-21 11:59:01 -08:00
parent f0ddebc740
commit 50740f253e
3 changed files with 15 additions and 14 deletions

View file

@ -5,6 +5,7 @@
HEAD HEAD
--------- ---------
- Add process/thread stats to Busy page [#4806]
- Refactor Web UI session usage. [#4804] - Refactor Web UI session usage. [#4804]
Numerous people have hit "Forbidden" errors and struggled with Sidekiq's Numerous people have hit "Forbidden" errors and struggled with Sidekiq's
Web UI session requirement. If you have code in your initializer for Web UI session requirement. If you have code in your initializer for
@ -29,9 +30,8 @@ If this is a bare Rack app, use a session middleware before Sidekiq::Web:
use Rack::Session::Cookie, secret: File.read(".session.key"), same_site: true, max_age: 86400 use Rack::Session::Cookie, secret: File.read(".session.key"), same_site: true, max_age: 86400
run Sidekiq::Web run Sidekiq::Web
``` ```
- Add process/thread count summary to Busy page [#4806]
6.1.3 6.1.3
--------- ---------
- Warn if Redis is configured to evict data under memory pressure [#4752] - Warn if Redis is configured to evict data under memory pressure [#4752]

View file

@ -63,6 +63,14 @@ module Sidekiq
opts.each { |key| set(key, false) } opts.each { |key| set(key, false) }
end end
def middlewares
@middlewares ||= []
end
def use(*args, &block)
middlewares << [args, block]
end
def set(attribute, value) def set(attribute, value)
send(:"#{attribute}=", value) send(:"#{attribute}=", value)
end end
@ -89,7 +97,7 @@ module Sidekiq
end end
def middlewares def middlewares
@middlewares ||= [] @middlewares ||= self.class.middlewares
end end
def use(*args, &block) def use(*args, &block)
@ -129,18 +137,11 @@ module Sidekiq
extension.registered(WebApplication) extension.registered(WebApplication)
end end
def default_middlewares
@default ||= [
[[Sidekiq::Web::CsrfProtection]],
[[Rack::ContentLength]]
]
end
private private
def build def build
klass = self.class klass = self.class
m = middlewares + default_middlewares m = middlewares
::Rack::Builder.new do ::Rack::Builder.new do
%w[stylesheets javascripts images].each do |asset_dir| %w[stylesheets javascripts images].each do |asset_dir|
@ -150,7 +151,7 @@ module Sidekiq
end end
m.each { |middleware, block| use(*middleware, &block) } m.each { |middleware, block| use(*middleware, &block) }
use Sidekiq::Web::CsrfProtection unless $TESTING
run WebApplication.new(klass) run WebApplication.new(klass)
end end
end end

View file

@ -18,7 +18,7 @@ describe Sidekiq::Web do
before do before do
Sidekiq.redis {|c| c.flushdb } Sidekiq.redis {|c| c.flushdb }
app.default_middlewares.clear app.middlewares.clear
end end
class WebWorker class WebWorker
@ -767,7 +767,7 @@ describe Sidekiq::Web do
app app
end end
it 'requires basic authentication' do it 'requires uses session options' do
get '/' get '/'
session_options = last_request.env['rack.session'].options session_options = last_request.env['rack.session'].options