From 515a1a332808eb7c2f9c006fc1903e1e8555b7fa Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 17 Jan 2009 10:16:31 -0600 Subject: Lock middleware has been committed upstream --- actionpack/lib/action_controller.rb | 1 - actionpack/lib/action_controller/lock.rb | 16 --------------- actionpack/lib/action_controller/middlewares.rb | 2 +- actionpack/lib/action_controller/rack_ext.rb | 24 ++-------------------- actionpack/lib/action_controller/rack_ext/lock.rb | 21 +++++++++++++++++++ .../lib/action_controller/rack_ext/multipart.rb | 22 ++++++++++++++++++++ 6 files changed, 46 insertions(+), 40 deletions(-) delete mode 100644 actionpack/lib/action_controller/lock.rb create mode 100644 actionpack/lib/action_controller/rack_ext/lock.rb create mode 100644 actionpack/lib/action_controller/rack_ext/multipart.rb diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb index f808bdd910..7a71c64695 100644 --- a/actionpack/lib/action_controller.rb +++ b/actionpack/lib/action_controller.rb @@ -56,7 +56,6 @@ module ActionController 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 c50762216e..0000000000 --- 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 0f038b8856..cbcb5cb3e4 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 3d6f1f9256..17cd08f39a 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 0000000000..9bf1889065 --- /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 0000000000..3d6f1f9256 --- /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 -- cgit v1.2.3