def respond_to(&block)
wants = {}
def wants.method_missing(type, *args, &handler)
::Sinatra::Base.send(:fail, "Unknown media type for respond_to: #{type}\nTry registering the extension with a mime type") if ::Sinatra::Base.mime_type(type).nil?
self[type] = handler
end
yield wants
if wants[format].nil?
alt = nil
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
end
raise UnhandledFormat if wants[format].nil?
wants[format].call
end