diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index f808bdd910f08a73cb4cf5bed3d05362e55abfb5..7a71c64695ec687cf96a647cf5710a7cf966bcdb 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -56,7 +56,6 @@ def self.load_all! autoload :Integration, 'action_controller/integration' autoload :IntegrationTest, 'action_controller/integration' autoload :Layout, 'action_controller/layout' - autoload :Lock, 'action_controller/lock' autoload :MiddlewareStack, 'action_controller/middleware_stack' autoload :MimeResponds, 'action_controller/mime_responds' autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes' diff --git a/actionpack/lib/action_controller/lock.rb b/actionpack/lib/action_controller/lock.rb deleted file mode 100644 index c50762216e05b1f88e2f950c2758a0fd8d22cd37..0000000000000000000000000000000000000000 --- a/actionpack/lib/action_controller/lock.rb +++ /dev/null @@ -1,16 +0,0 @@ -module ActionController - class Lock - FLAG = 'rack.multithread'.freeze - - def initialize(app, lock = Mutex.new) - @app, @lock = app, lock - end - - def call(env) - old, env[FLAG] = env[FLAG], false - @lock.synchronize { @app.call(env) } - ensure - env[FLAG] = old - end - end -end diff --git a/actionpack/lib/action_controller/middlewares.rb b/actionpack/lib/action_controller/middlewares.rb index 0f038b8856f563326a286a00c1e588cac069d6e3..cbcb5cb3e417e3d768eceac0b964557e2172fde5 100644 --- a/actionpack/lib/action_controller/middlewares.rb +++ b/actionpack/lib/action_controller/middlewares.rb @@ -1,4 +1,4 @@ -use "ActionController::Lock", :if => lambda { +use "Rack::Lock", :if => lambda { !ActionController::Base.allow_concurrency } diff --git a/actionpack/lib/action_controller/rack_ext.rb b/actionpack/lib/action_controller/rack_ext.rb index 3d6f1f9256c8bf6cb1ced2d175ce2d1c03b64c19..17cd08f39a318cf800815e3307d070fb9d5e07b1 100644 --- a/actionpack/lib/action_controller/rack_ext.rb +++ b/actionpack/lib/action_controller/rack_ext.rb @@ -1,22 +1,2 @@ -module Rack - module Utils - module Multipart - class << self - def parse_multipart_with_rewind(env) - result = parse_multipart_without_rewind(env) - - begin - env['rack.input'].rewind - rescue NoMethodError, Errno::ESPIPE - # Handles exceptions raised by input streams that cannot be rewound - # such as when using plain CGI under Apache - end - - result - end - - alias_method_chain :parse_multipart, :rewind - end - end - end -end +require 'action_controller/rack_ext/lock' +require 'action_controller/rack_ext/multipart' diff --git a/actionpack/lib/action_controller/rack_ext/lock.rb b/actionpack/lib/action_controller/rack_ext/lock.rb new file mode 100644 index 0000000000000000000000000000000000000000..9bf1889065af7f0f9594786667208aa47b4b09af --- /dev/null +++ b/actionpack/lib/action_controller/rack_ext/lock.rb @@ -0,0 +1,21 @@ +module Rack + # Rack::Lock was commited to Rack core + # http://github.com/rack/rack/commit/7409b0c + # Remove this when Rack 1.0 is released + unless defined? Lock + class Lock + FLAG = 'rack.multithread'.freeze + + def initialize(app, lock = Mutex.new) + @app, @lock = app, lock + end + + def call(env) + old, env[FLAG] = env[FLAG], false + @lock.synchronize { @app.call(env) } + ensure + env[FLAG] = old + end + end + end +end diff --git a/actionpack/lib/action_controller/rack_ext/multipart.rb b/actionpack/lib/action_controller/rack_ext/multipart.rb new file mode 100644 index 0000000000000000000000000000000000000000..3d6f1f9256c8bf6cb1ced2d175ce2d1c03b64c19 --- /dev/null +++ b/actionpack/lib/action_controller/rack_ext/multipart.rb @@ -0,0 +1,22 @@ +module Rack + module Utils + module Multipart + class << self + def parse_multipart_with_rewind(env) + result = parse_multipart_without_rewind(env) + + begin + env['rack.input'].rewind + rescue NoMethodError, Errno::ESPIPE + # Handles exceptions raised by input streams that cannot be rewound + # such as when using plain CGI under Apache + end + + result + end + + alias_method_chain :parse_multipart, :rewind + end + end + end +end