# File lib/sinatra/respond_to.rb, line 204
      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?
          # Loop through request.accept in prioritized order looking for a Mime Type having a format
          # that is recognized.
          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