Permalink
Browse files

Revert "fix the Flash middleware loading the session on every request…

… (very dangerous especially with Rack::Cache), it should only be loaded when the flash method is called"

This reverts commits e3069c6 and 2b2983d.

Reason: This add a non-backward compatible change in the way that flash
works now (swept in every request).
  • Loading branch information...
1 parent f7cde3e commit 3cba6eee66a4c25b93839ea6fd1da08d7780f2de @rafaelfranca rafaelfranca committed Jun 5, 2012
@@ -460,6 +460,7 @@ 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
build_request_uri(action, 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).tap(&:sweep)
+ @env[Flash::KEY] ||= (session["flash"] || Flash::FlashHash.new)
end
end
@@ -235,6 +235,10 @@ 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'] || {}
@@ -251,8 +255,7 @@ def call(env)
env[KEY] = new_hash
end
- if (!session.respond_to?(:loaded?) || session.loaded?) && # (reset_session uses {}, which doesn't implement #loaded?)
- session.key?('flash') && session['flash'].empty?
+ if session.key?('flash') && session['flash'].empty?
session.delete('flash')
end
end
@@ -26,25 +26,5 @@ def app
require "#{app_path}/config/environment"
assert app.config.session_options[:secure], "Expected session to be marked as secure"
end
-
- test "session is not loaded if it's not used" do
- make_basic_app
-
- class ::OmgController < ActionController::Base
- def index
- if params[:flash]
- flash[:notice] = "notice"
- end
-
- render :nothing => true
- end
- end
-
- get "/?flash=true"
- get "/"
-
- assert last_request.env["HTTP_COOKIE"]
- assert !last_response.headers["Set-Cookie"]
- end
end
end

0 comments on commit 3cba6ee

Please sign in to comment.