Permalink
Browse files

fix the Flash middleware loading the session on every request (very d…

…angerous especially with Rack::Cache), it should only be loaded when the flash method is called
  • Loading branch information...
willbryant committed Jan 23, 2012
1 parent 1b4e6ca commit 037804db4e41e725ae3577fd3f07fe718478107c
@@ -454,7 +454,6 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
@request.session = ActionController::TestSession.new(session) if session
@request.session["flash"] = @request.flash.update(flash || {})
- @request.session["flash"].sweep
@controller.request = @request
@controller.params.merge!(parameters)
@@ -4,7 +4,7 @@ class Request
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
# to put a new one.
def flash
- @env[Flash::KEY] ||= (session["flash"] || Flash::FlashHash.new)
+ @env[Flash::KEY] ||= (session["flash"] || Flash::FlashHash.new).tap(&:sweep)
end
end
@@ -235,10 +235,6 @@ def initialize(app)
end
def call(env)
- if (session = env['rack.session']) && (flash = session['flash'])
- flash.sweep
- end
-
@app.call(env)
ensure
session = env['rack.session'] || {}
@@ -255,7 +251,8 @@ def call(env)
env[KEY] = new_hash
end
- if session.key?('flash') && session['flash'].empty?
+ if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)
+ session.key?('flash') && session['flash'].empty?
session.delete('flash')
end
end

0 comments on commit 037804d

Please sign in to comment.