Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/sinatra/respond_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ def wants.method_missing(type, *args, &handler)
request.accept.each do |mime_type|
break if alt = wants.keys.detect {|k| ::Sinatra::Base.mime_type(k) == mime_type}
end
format alt if alt
if alt
format alt
elsif request.accept.include?("*.*")
format settings.default_content
end
end
raise UnhandledFormat if wants[format].nil?
wants[format].call
Expand Down
6 changes: 6 additions & 0 deletions spec/extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def mime_type(sym)
last_response.body.should =~ %r{'Hiya from javascript'}
last_response.content_type.should include(mime_type(:js))
end

it "should use default_content when the first Accept header includes the wildcard" do
get "/resource", {}, {'HTTP_ACCEPT' => "text/csv;q=0.9,*.*;q=0.8"}
last_response.body.should =~ %r{\s*<html>\s*<body>Hello from HTML</body>\s*</html>\s*}
last_response.content_type.should include(mime_type(:html))
end
end

describe "routes not using respond_to" do
Expand Down