server/lib/sinatra/rack_accept.rb
# This code was inherited from respond_to plugin
# http://github.com/cehoffman/sinatra-respond_to
#
# This method is used to overide the default content_type returned from
# rack-accept middleware.


This method is used to overide the default content_type returned from
rack-accept middleware.
This method is used to overide the default content_type returned from rack - accept middleware .
def respond_to(&block)
        wants = {}
        def wants.method_missing(type, *args, &handler)
          self[type] = handler
        end
        yield wants
        if request.env["SCRIPT_NAME"].include?("cimi") || Deltacloud.default_frontend.name == :cimi
          if ([:json, :xml] & accepting_formats.keys).empty?
            request.env['rack-accept.formats'] = {:json=>0}
          end
          @media_type = (accepting_formats.has_key?(:xml) ? [:xml, accepting_formats[:xml]] : nil)
        end if Deltacloud.respond_to? :default_frontend
        @media_type ||= accepting_formats.to_a.sort { |a,b| a[1]<=>b[1] }.reverse.select do |format, priority|
          wants.keys.include?(format) == true
        end.first
        if @media_type and @media_type.kind_of? Symbol
          @media_type = [ @media_type ]
        end
        if @media_type and @media_type[0]
          @media_type = @media_type[0]
          if  Rack::MediaType::ACCEPTED_MEDIA_TYPES[@media_type]
            headers 'Content-Type' => Rack::MediaType::ACCEPTED_MEDIA_TYPES[@media_type][:return]
          else
            headers 'Content-Type' => 'application/xml'
          end
          wants[@media_type.to_sym].call if wants[@media_type.to_sym]
        else
          headers 'Content-Type' => nil
          status 406
        end
      end
def respond_to ( & block ) wants = { } def wants . method_missing ( type , * args , & handler ) self [ type ] = handler end yield wants if request . env [ "SCRIPT_NAME" ] . include? ( "cimi" ) || Deltacloud . default_frontend . name == :cimi if ( [ :json , :xml ] & accepting_formats . keys ) . empty? request . env [ 'rack-accept.formats' ] = { :json => 0 } end @media_type = ( accepting_formats . has_key? ( :xml ) ? [ :xml , accepting_formats [ :xml ] ] : nil ) end if Deltacloud . respond_to? :default_frontend @media_type ||= accepting_formats . to_a . sort { | a , b | a [ 1 ] <=> b [ 1 ] } . reverse . select do | format , priority | wants . keys . include? ( format ) == true end . first if @media_type and @media_type . kind_of? Symbol @media_type = [ @media_type ] end if @media_type and @media_type [ 0 ] @media_type = @media_type [ 0 ] if Rack :: MediaType :: ACCEPTED_MEDIA_TYPES [ @media_type ] headers 'Content-Type' => Rack :: MediaType :: ACCEPTED_MEDIA_TYPES [ @media_type ] [ :return ] else headers 'Content-Type' => 'application/xml' end wants [ @media_type . to_sym ] . call if wants [ @media_type . to_sym ] else headers 'Content-Type' => nil status 406 end end
This code was inherited from respond_to plugin
http://github.com/cehoffman/sinatra-respond_to
This code was inherited from respond_to plugin http : // github . com / cehoffman / sinatra - respond_to
#when cimi and neither json or xml defined... default to _something_  -  json?
block
<not_specific>