mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Get rid of the close checks since we cannot reliably close the session anyway.
This commit is contained in:
parent
8015f906d5
commit
d142572567
7 changed files with 1 additions and 165 deletions
|
@ -63,7 +63,6 @@ module ActionDispatch
|
|||
autoload :Static
|
||||
end
|
||||
|
||||
autoload :ClosedError, 'action_dispatch/middleware/closed_error'
|
||||
autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
|
||||
autoload :Routing
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
module ActionDispatch
|
||||
class ClosedError < StandardError #:nodoc:
|
||||
def initialize(kind)
|
||||
super "Cannot modify #{kind} because it was closed. This means it was already streamed back to the client or converted to HTTP headers."
|
||||
end
|
||||
end
|
||||
end
|
|
@ -121,10 +121,6 @@ module ActionDispatch
|
|||
@cookies = {}
|
||||
end
|
||||
|
||||
attr_reader :closed
|
||||
alias :closed? :closed
|
||||
def close!; @closed = true end
|
||||
|
||||
def each(&block)
|
||||
@cookies.each(&block)
|
||||
end
|
||||
|
@ -165,7 +161,6 @@ module ActionDispatch
|
|||
# Sets the cookie named +name+. The second argument may be the very cookie
|
||||
# value, or a hash of options as documented above.
|
||||
def []=(key, options)
|
||||
raise ClosedError, :cookies if closed?
|
||||
if options.is_a?(Hash)
|
||||
options.symbolize_keys!
|
||||
value = options[:value]
|
||||
|
@ -259,7 +254,6 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def []=(key, options)
|
||||
raise ClosedError, :cookies if closed?
|
||||
if options.is_a?(Hash)
|
||||
options.symbolize_keys!
|
||||
else
|
||||
|
@ -298,7 +292,6 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def []=(key, options)
|
||||
raise ClosedError, :cookies if closed?
|
||||
if options.is_a?(Hash)
|
||||
options.symbolize_keys!
|
||||
options[:value] = @verifier.generate(options[:value])
|
||||
|
@ -352,9 +345,6 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
[status, headers, body]
|
||||
ensure
|
||||
cookie_jar = ActionDispatch::Request.new(env).cookie_jar unless cookie_jar
|
||||
cookie_jar.close!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -93,7 +93,6 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def []=(k, v) #:nodoc:
|
||||
raise ClosedError, :flash if closed?
|
||||
keep(k)
|
||||
@flashes[k] = v
|
||||
end
|
||||
|
@ -159,10 +158,6 @@ module ActionDispatch
|
|||
@now ||= FlashNow.new(self)
|
||||
end
|
||||
|
||||
attr_reader :closed
|
||||
alias :closed? :closed
|
||||
def close!; @closed = true; end
|
||||
|
||||
# Keeps either the entire current flash or a specific flash entry available for the next action:
|
||||
#
|
||||
# flash.keep # keeps the entire flash
|
||||
|
@ -258,7 +253,6 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
env[KEY] = new_hash
|
||||
new_hash.close!
|
||||
end
|
||||
|
||||
if session.key?('flash') && session['flash'].empty?
|
||||
|
|
|
@ -74,10 +74,6 @@ module ActionDispatch
|
|||
class AbstractStore < Rack::Session::Abstract::ID
|
||||
include Compatibility
|
||||
include StaleSessionCheck
|
||||
|
||||
def destroy_session(env, sid, options)
|
||||
raise '#destroy_session needs to be implemented.'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -254,16 +254,6 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
def test_setting_flash_raises_after_stream_back_to_client
|
||||
with_test_route_set do
|
||||
env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new }
|
||||
get '/set_flash', nil, env
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
@request.flash['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_flash_does_not_raise_in_following_requests
|
||||
with_test_route_set do
|
||||
env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new }
|
||||
|
@ -280,36 +270,6 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
def test_setting_flash_raises_after_stream_back_to_client_even_with_an_empty_flash
|
||||
with_test_route_set do
|
||||
env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new }
|
||||
get '/dont_set_flash', nil, env
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
@request.flash['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_flash_now_raises_after_stream_back_to_client
|
||||
with_test_route_set do
|
||||
env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new }
|
||||
get '/set_flash_now', nil, env
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
@request.flash.now['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_flash_now_raises_after_stream_back_to_client_even_with_an_empty_flash
|
||||
with_test_route_set do
|
||||
env = { 'action_dispatch.request.flash_hash' => ActionDispatch::Flash::FlashHash.new }
|
||||
get '/dont_set_flash', nil, env
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
@request.flash.now['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Overwrite get to send SessionSecret in env hash
|
||||
|
|
|
@ -564,100 +564,4 @@ class CookiesTest < ActionController::TestCase
|
|||
assert_not_equal expected.split("\n"), header
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class CookiesIntegrationTest < ActionDispatch::IntegrationTest
|
||||
SessionKey = '_myapp_session'
|
||||
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
|
||||
|
||||
class TestController < ActionController::Base
|
||||
def dont_set_cookies
|
||||
head :ok
|
||||
end
|
||||
|
||||
def set_cookies
|
||||
cookies["that"] = "hello"
|
||||
head :ok
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_cookies_raises_after_stream_back_to_client
|
||||
with_test_route_set do
|
||||
get '/set_cookies'
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
request.cookie_jar['alert'] = 'alert'
|
||||
cookies['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_cookies_raises_after_stream_back_to_client_even_without_cookies
|
||||
with_test_route_set do
|
||||
get '/dont_set_cookies'
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
request.cookie_jar['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_permanent_cookies_raises_after_stream_back_to_client
|
||||
with_test_route_set do
|
||||
get '/set_cookies'
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
request.cookie_jar.permanent['alert'] = 'alert'
|
||||
cookies['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_permanent_cookies_raises_after_stream_back_to_client_even_without_cookies
|
||||
with_test_route_set do
|
||||
get '/dont_set_cookies'
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
request.cookie_jar.permanent['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_signed_cookies_raises_after_stream_back_to_client
|
||||
with_test_route_set do
|
||||
get '/set_cookies'
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
request.cookie_jar.signed['alert'] = 'alert'
|
||||
cookies['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def test_setting_signed_cookies_raises_after_stream_back_to_client_even_without_cookies
|
||||
with_test_route_set do
|
||||
get '/dont_set_cookies'
|
||||
assert_raise(ActionDispatch::ClosedError) {
|
||||
request.cookie_jar.signed['alert'] = 'alert'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Overwrite get to send SessionSecret in env hash
|
||||
def get(path, parameters = nil, env = {})
|
||||
env["action_dispatch.secret_token"] ||= SessionSecret
|
||||
super
|
||||
end
|
||||
|
||||
def with_test_route_set
|
||||
with_routing do |set|
|
||||
set.draw do
|
||||
match ':action', :to => CookiesIntegrationTest::TestController
|
||||
end
|
||||
|
||||
@app = self.class.build_app(set) do |middleware|
|
||||
middleware.use ActionDispatch::Cookies
|
||||
middleware.delete "ActionDispatch::ShowExceptions"
|
||||
end
|
||||
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue