diff --git a/padrino-core/lib/padrino-core/application/routing.rb b/padrino-core/lib/padrino-core/application/routing.rb index 693be3ff5..2026cf084 100644 --- a/padrino-core/lib/padrino-core/application/routing.rb +++ b/padrino-core/lib/padrino-core/application/routing.rb @@ -503,9 +503,14 @@ def provides(*types) condition do mime_types = types.map { |t| mime_type(t) } accepts = request.accept.map { |a| a.split(";")[0].strip } - matching_types = (accepts & mime_types) request.path_info =~ /\.([^\.\/]+)$/ url_format = $1.to_sym if $1 + + if accepts.any? { |a| a == "*/*" } + matching_types = mime_types.slice(0,1) + else + matching_types = (accepts & mime_types) + end if params[:format] accept_format = params[:format] @@ -517,7 +522,6 @@ def provides(*types) matched_format = types.include?(:any) || types.include?(accept_format) || types.include?(url_format) || - accepts.any? { |a| a == "*/*" } || ((!url_format) && request.accept.empty? && types.include?(:html)) # per rfc: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html diff --git a/padrino-core/test/test_routing.rb b/padrino-core/test/test_routing.rb index d77e08b2c..62a526ab9 100644 --- a/padrino-core/test/test_routing.rb +++ b/padrino-core/test/test_routing.rb @@ -178,6 +178,15 @@ class TestRouting < Test::Unit::TestCase get "/a", {}, {"HTTP_ACCEPT" => "application/yaml"} assert_equal 406, status end + + should "not set content_type to :html if Accept */* and html not in provides" do + mock_app do + get("/foo", :provides => [:json, :xml]) { content_type.to_s } + end + + get '/foo', {}, { 'HTTP_ACCEPT' => '*/*;q=0.5' } + assert_equal 'json', body + end should "not default to HTML if HTML is not provided and no type is given" do mock_app do