diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-20 14:55:13 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-01-20 14:55:13 +0000 |
commit | dfed3d309e26c11ba4132aaf4c3cd25ad3b2c905 (patch) | |
tree | c1310189b961850f154406b4fd9ef72ffaefb1ac /actionpack/lib/action_controller/cgi_ext | |
parent | 93f7cb2a80b53d38eb01aaeade8f5c8bf13090f2 (diff) | |
download | rails-dfed3d309e26c11ba4132aaf4c3cd25ad3b2c905.tar.gz rails-dfed3d309e26c11ba4132aaf4c3cd25ad3b2c905.tar.bz2 rails-dfed3d309e26c11ba4132aaf4c3cd25ad3b2c905.zip |
A few missing files
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@468 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/cgi_ext')
-rw-r--r-- | actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb b/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb new file mode 100644 index 0000000000..b494674c91 --- /dev/null +++ b/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb @@ -0,0 +1,44 @@ +class CGI #:nodoc: + # Add @request.env['RAW_POST_DATA'] for the vegans. + module QueryExtension + # Initialize the data from the query. + # + # Handles multipart forms (in particular, forms that involve file uploads). + # Reads query parameters in the @params field, and cookies into @cookies. + def initialize_query() + if boundary = multipart_form_boundary + @multipart = true + @params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH'])) + else + @multipart = false + @params = CGI::parse(read_query_params) + end + end + + private + def multipart_form_boundary + multipart_form_boundary_re = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n # " ruby-mode + + if env_table['REQUEST_METHOD'] == 'POST' + multipart_form_boundary_re.match(env_table['CONTENT_TYPE']).to_a.pop + end + end + + def read_query_params + case env_table['REQUEST_METHOD'] + when 'GET', 'HEAD' + if defined? MOD_RUBY + Apache::request.args or '' + else + env_table['QUERY_STRING'] or '' + end + when 'POST' + stdinput.binmode if stdinput.respond_to?(:binmode) + content = stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or '' + env_table['RAW_POST_DATA'] = content.freeze + else + read_from_cmdline + end + end + end # module QueryExtension +end
\ No newline at end of file |