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/rack_ext/lock.rb | 21 +++++++++++++++++++++ .../lib/action_controller/rack_ext/multipart.rb | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 actionpack/lib/action_controller/rack_ext/lock.rb create mode 100644 actionpack/lib/action_controller/rack_ext/multipart.rb (limited to 'actionpack/lib/action_controller/rack_ext') 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 From 29e7a0242853a5e102b6846b87723fc26a1ffb08 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 17 Jan 2009 11:12:18 -0600 Subject: Ensure any method sent to RewindableIO reads the original IO object [#1767 state:resolved] --- actionpack/lib/action_controller/rack_ext/multipart.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller/rack_ext') diff --git a/actionpack/lib/action_controller/rack_ext/multipart.rb b/actionpack/lib/action_controller/rack_ext/multipart.rb index 3d6f1f9256..3b142307e9 100644 --- a/actionpack/lib/action_controller/rack_ext/multipart.rb +++ b/actionpack/lib/action_controller/rack_ext/multipart.rb @@ -6,8 +6,8 @@ module Rack result = parse_multipart_without_rewind(env) begin - env['rack.input'].rewind - rescue NoMethodError, Errno::ESPIPE + env['rack.input'].rewind if env['rack.input'].respond_to?(:rewind) + rescue Errno::ESPIPE # Handles exceptions raised by input streams that cannot be rewound # such as when using plain CGI under Apache end -- cgit v1.2.3 From ff0a2678c4bce9da348e1263915558795e3a3640 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 17 Jan 2009 20:29:50 -0600 Subject: Build query string and POST params parser on top of Rack::Request. Also switch our multipart parser to use Racks. Moved XML, JSON, and YAML parsers into ActionController::ParamsParser middleware [#1661 state:resolved] --- .../lib/action_controller/rack_ext/parse_query.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 actionpack/lib/action_controller/rack_ext/parse_query.rb (limited to 'actionpack/lib/action_controller/rack_ext') diff --git a/actionpack/lib/action_controller/rack_ext/parse_query.rb b/actionpack/lib/action_controller/rack_ext/parse_query.rb new file mode 100644 index 0000000000..2f21a57770 --- /dev/null +++ b/actionpack/lib/action_controller/rack_ext/parse_query.rb @@ -0,0 +1,18 @@ +# Rack does not automatically cleanup Safari 2 AJAX POST body +# This has not yet been commited to Rack, please +1 this ticket: +# http://rack.lighthouseapp.com/projects/22435/tickets/19 + +module Rack + module Utils + alias_method :parse_query_without_ajax_body_cleanup, :parse_query + module_function :parse_query_without_ajax_body_cleanup + + def parse_query(qs, d = '&;') + qs = qs.dup + qs.chop! if qs[-1] == 0 + qs.gsub!(/&_=$/, '') + parse_query_without_ajax_body_cleanup(qs, d) + end + module_function :parse_query + end +end -- cgit v1.2.3