提交 515a1a33 编写于 作者: J Joshua Peek

Lock middleware has been committed upstream

上级 3ee4e009
......@@ -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'
......
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
use "ActionController::Lock", :if => lambda {
use "Rack::Lock", :if => lambda {
!ActionController::Base.allow_concurrency
}
......
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'
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
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册