aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/cgi_ext
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-05-15 21:36:21 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-05-15 21:36:21 +0000
commit32d03af341eba4d0b263156f0241016b857c4d84 (patch)
tree5638dfcd579382a3de546f9fc3b5f3b94473f1ef /actionpack/lib/action_controller/cgi_ext
parent9e3a51eb6cc6f54c861c808c15bf8895d14aa023 (diff)
downloadrails-32d03af341eba4d0b263156f0241016b857c4d84.tar.gz
rails-32d03af341eba4d0b263156f0241016b857c4d84.tar.bz2
rails-32d03af341eba4d0b263156f0241016b857c4d84.zip
Introduce the request.body stream. Lazy-read to parse parameters rather than always setting RAW_POST_DATA. Reduces the memory footprint of large binary PUT requests.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6740 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/cgi_ext')
-rw-r--r--actionpack/lib/action_controller/cgi_ext/parameters.rb20
-rw-r--r--actionpack/lib/action_controller/cgi_ext/query_extension.rb10
-rw-r--r--actionpack/lib/action_controller/cgi_ext/stdinput.rb23
3 files changed, 31 insertions, 22 deletions
diff --git a/actionpack/lib/action_controller/cgi_ext/parameters.rb b/actionpack/lib/action_controller/cgi_ext/parameters.rb
index 639f131e00..a7f5393272 100644
--- a/actionpack/lib/action_controller/cgi_ext/parameters.rb
+++ b/actionpack/lib/action_controller/cgi_ext/parameters.rb
@@ -1,16 +1,6 @@
require 'cgi'
require 'strscan'
-class CGI #:nodoc:
- class << self
- alias :escapeHTML_fail_on_nil :escapeHTML
-
- def escapeHTML(string)
- escapeHTML_fail_on_nil(string) unless string.nil?
- end
- end
-end
-
module ActionController
module CgiExt
module Parameters
@@ -72,18 +62,18 @@ module ActionController
parser.result
end
- def parse_formatted_request_parameters(mime_type, raw_post_data)
+ def parse_formatted_request_parameters(mime_type, body)
case strategy = ActionController::Base.param_parsers[mime_type]
when Proc
- strategy.call(raw_post_data)
+ strategy.call(body)
when :xml_simple, :xml_node
- raw_post_data.blank? ? {} : Hash.from_xml(raw_post_data).with_indifferent_access
+ body.blank? ? {} : Hash.from_xml(body).with_indifferent_access
when :yaml
- YAML.load(raw_post_data)
+ YAML.load(body)
end
rescue Exception => e # YAML, XML or Ruby code block errors
{ "exception" => "#{e.message} (#{e.class})", "backtrace" => e.backtrace,
- "raw_post_data" => raw_post_data, "format" => mime_type }
+ "body" => body, "format" => mime_type }
end
private
diff --git a/actionpack/lib/action_controller/cgi_ext/query_extension.rb b/actionpack/lib/action_controller/cgi_ext/query_extension.rb
index 9e836eaaf8..147530b5ce 100644
--- a/actionpack/lib/action_controller/cgi_ext/query_extension.rb
+++ b/actionpack/lib/action_controller/cgi_ext/query_extension.rb
@@ -31,18 +31,14 @@ class CGI #:nodoc:
# Set multipart to false by default.
@multipart = false
- # POST and PUT may have params in entity body. If content type is
- # missing for POST, assume urlencoded. If content type is missing
- # for PUT, don't assume anything and don't parse the parameters:
- # it's likely binary data.
- #
- # The other HTTP methods have their params in the query string.
+ # POST and PUT may have params in entity body. If content type is missing
+ # or non-urlencoded, don't read the body or parse parameters: assume it's
+ # binary data.
if method == :post || method == :put
if boundary = extract_multipart_form_boundary(content_type)
@multipart = true
@params = read_multipart(boundary, content_length)
elsif content_type.blank? || content_type !~ %r{application/x-www-form-urlencoded}i
- read_params(method, content_length)
@params = {}
end
end
diff --git a/actionpack/lib/action_controller/cgi_ext/stdinput.rb b/actionpack/lib/action_controller/cgi_ext/stdinput.rb
new file mode 100644
index 0000000000..b0ca63ef2f
--- /dev/null
+++ b/actionpack/lib/action_controller/cgi_ext/stdinput.rb
@@ -0,0 +1,23 @@
+require 'cgi'
+
+module ActionController
+ module CgiExt
+ # Publicize the CGI's internal input stream so we can lazy-read
+ # request.body. Make it writable so we don't have to play $stdin games.
+ module Stdinput
+ def self.included(base)
+ base.class_eval do
+ remove_method :stdinput
+ attr_accessor :stdinput
+ end
+
+ base.alias_method_chain :initialize, :stdinput
+ end
+
+ def initialize_with_stdinput(type = nil, stdinput = $stdin)
+ @stdinput = stdinput
+ initialize_without_stdinput(type || 'query')
+ end
+ end
+ end
+end