diff options
author | wycats <wycats@gmail.com> | 2010-03-28 13:40:38 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-03-28 13:40:38 -0700 |
commit | 77a2a3d9b3aa461437ced326ea4a70112a8c68ed (patch) | |
tree | eb236e6832815f95629d4b00a475e19dc2e575aa /actionpack | |
parent | e1a70faea675499d717cef7662262ceb03b23975 (diff) | |
download | rails-77a2a3d9b3aa461437ced326ea4a70112a8c68ed.tar.gz rails-77a2a3d9b3aa461437ced326ea4a70112a8c68ed.tar.bz2 rails-77a2a3d9b3aa461437ced326ea4a70112a8c68ed.zip |
Request#content_type exists in Rack::Request, and other parts of Rack::Request expect
it to return a String. Split the Rails API so that Request#content_type returns
a String, and Request#content_mime_type returns a Mime::Type object.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_negotiation.rb | 8 | ||||
-rwxr-xr-x | actionpack/lib/action_dispatch/http/request.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/params_parser.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/rack_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 8 |
5 files changed, 20 insertions, 14 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index fec250e928..be89924015 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -5,7 +5,7 @@ module ActionDispatch # # For backward compatibility, the post \format is extracted from the # X-Post-Data-Format HTTP header if present. - def content_type + def content_mime_type @env["action_dispatch.request.content_type"] ||= begin if @env['CONTENT_TYPE'] =~ /^([^,\;]*)/ Mime::Type.lookup($1.strip.downcase) @@ -15,13 +15,17 @@ module ActionDispatch end end + def content_type + content_mime_type && content_mime_type.to_s + end + # Returns the accepted MIME type for the request. def accepts @env["action_dispatch.request.accepts"] ||= begin header = @env['HTTP_ACCEPT'].to_s.strip if header.empty? - [content_type] + [content_mime_type] else Mime::Type.parse(header) end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index ea9f0f99c2..8b8426b5aa 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -96,11 +96,11 @@ module ActionDispatch end def forgery_whitelisted? - method == :get || xhr? || content_type.nil? || !content_type.verify_request? + method == :get || xhr? || content_mime_type.nil? || !content_mime_type.verify_request? end def media_type - content_type.to_s + content_mime_type.to_s end # Returns the content length of the request as an integer. @@ -157,7 +157,7 @@ module ActionDispatch end def form_data? - FORM_DATA_MEDIA_TYPES.include?(content_type.to_s) + FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s) end def body_stream #:nodoc: diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb index f4c4324fb0..18a3688bb0 100644 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ b/actionpack/lib/action_dispatch/middleware/params_parser.rb @@ -25,7 +25,9 @@ module ActionDispatch return false if request.content_length.zero? - mime_type = content_type_from_legacy_post_data_format_header(env) || request.content_type + mime_type = content_type_from_legacy_post_data_format_header(env) || + request.content_mime_type + strategy = @parsers[mime_type] return false unless strategy @@ -53,7 +55,7 @@ module ActionDispatch raise { "body" => request.raw_post, - "content_type" => request.content_type, + "content_type" => request.content_mime_type, "content_length" => request.content_length, "exception" => "#{e.message} (#{e.class})", "backtrace" => e.backtrace } diff --git a/actionpack/test/dispatch/rack_test.rb b/actionpack/test/dispatch/rack_test.rb index 94eba2a24f..504bebbb86 100644 --- a/actionpack/test/dispatch/rack_test.rb +++ b/actionpack/test/dispatch/rack_test.rb @@ -122,7 +122,7 @@ class RackRequestTest < BaseRackTest test "cgi environment variables" do assert_equal "Basic", @request.auth_type assert_equal 0, @request.content_length - assert_equal nil, @request.content_type + assert_equal nil, @request.content_mime_type assert_equal "CGI/1.1", @request.gateway_interface assert_equal "*/*", @request.accept assert_equal "UTF-8", @request.accept_charset @@ -177,12 +177,12 @@ end class RackRequestContentTypeTest < BaseRackTest test "html content type verification" do @request.env['CONTENT_TYPE'] = Mime::HTML.to_s - assert @request.content_type.verify_request? + assert @request.content_mime_type.verify_request? end test "xml content type verification" do @request.env['CONTENT_TYPE'] = Mime::XML.to_s - assert !@request.content_type.verify_request? + assert !@request.content_mime_type.verify_request? end end diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index badef4e92e..9093e1ed65 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -295,7 +295,7 @@ class RequestTest < ActiveSupport::TestCase test "content type" do request = stub_request 'CONTENT_TYPE' => 'text/html' - assert_equal Mime::HTML, request.content_type + assert_equal Mime::HTML, request.content_mime_type end test "can override format with parameter" do @@ -310,17 +310,17 @@ class RequestTest < ActiveSupport::TestCase test "no content type" do request = stub_request - assert_equal nil, request.content_type + assert_equal nil, request.content_mime_type end test "content type is XML" do request = stub_request 'CONTENT_TYPE' => 'application/xml' - assert_equal Mime::XML, request.content_type + assert_equal Mime::XML, request.content_mime_type end test "content type with charset" do request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8' - assert_equal Mime::XML, request.content_type + assert_equal Mime::XML, request.content_mime_type end test "user agent" do |