aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb')
-rw-r--r--actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb51
1 files changed, 31 insertions, 20 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
index b2194eb07b..20fc6ff47f 100644
--- a/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb
+++ b/actionpack/lib/action_controller/cgi_ext/raw_post_data_fix.rb
@@ -6,14 +6,21 @@ class CGI #:nodoc:
# Handles multipart forms (in particular, forms that involve file uploads).
# Reads query parameters in the @params field, and cookies into @cookies.
def initialize_query()
- @cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] || env_table['COOKIE']))
+ @cookies = CGI::Cookie::parse(env_table['HTTP_COOKIE'] || env_table['COOKIE'])
- if boundary = multipart_form_boundary
+ #fix some strange request environments
+ if method = env_table['REQUEST_METHOD']
+ method = method.to_s.downcase.intern
+ else
+ method = :get
+ end
+
+ if method == :post && (boundary = multipart_form_boundary)
@multipart = true
@params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
else
@multipart = false
- @params = CGI::parse(read_query_params || "")
+ @params = CGI::parse(read_query_params(method) || "")
end
end
@@ -22,21 +29,23 @@ class CGI #:nodoc:
MULTIPART_FORM_BOUNDARY_RE = %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n #"
end
- def multipart_form_boundary
- if env_table['REQUEST_METHOD'] == 'POST'
- MULTIPART_FORM_BOUNDARY_RE.match(env_table['CONTENT_TYPE']).to_a.pop
- end
+ def multipart_form_boundary
+ MULTIPART_FORM_BOUNDARY_RE.match(env_table['CONTENT_TYPE']).to_a.pop
end
- def read_params_from_query
- if defined? MOD_RUBY
+ if defined? MOD_RUBY
+ def read_params_from_query
Apache::request.args || ''
- else
- # fixes CGI querystring parsing for POSTs
- if env_table['QUERY_STRING'].blank? && !env_table['REQUEST_URI'].blank?
- env_table['QUERY_STRING'] = env_table['REQUEST_URI'].split('?', 2)[1] || ''
+ end
+ else
+ def read_params_from_query
+ # fixes CGI querystring parsing for lighttpd
+ env_qs = env_table['QUERY_STRING']
+ if env_qs.blank? && !(uri=env_table['REQUEST_URI']).blank?
+ env_qs.replace(uri.split('?', 2)[1] || '')
+ else
+ env_qs
end
- env_table['QUERY_STRING']
end
end
@@ -46,13 +55,15 @@ class CGI #:nodoc:
env_table['RAW_POST_DATA'] = content.split("&_").first.to_s.freeze # &_ is a fix for Safari Ajax postings that always append \000
end
- def read_query_params
- case env_table['REQUEST_METHOD'].to_s.upcase
- when 'CMD'
- read_from_cmdline
- when 'POST', 'PUT'
+ def read_query_params(method)
+ case method
+ when :get
+ read_params_from_query
+ when :post, :put
read_params_from_post
- else # when 'GET', 'HEAD', 'DELETE', 'OPTIONS'
+ when :cmd
+ read_from_cmdline
+ else # when :head, :delete, :options
read_params_from_query
end
end