def derive_content_type(handler_name)
      possible_values = if self.content_type.match 'text/plain'
        _, content_type_attribute = self.headers_attribute && self.headers_attribute.attributes.find { |k,v| k.to_s =~ /^content[-_]{1}type$/i }
        if content_type_attribute && content_type_attribute.options.key?(:values)
          content_type_attribute.options[:values]
        else
          []
        end
      else
        [self.content_type]
      end

      # generic default encoding is the best we can do
      if possible_values.empty?
        return MediaTypeIdentifier.load("application/#{handler_name}")
      end

      # if any defined value match the preferred handler_name, return it
      possible_values.each do |ct|
        mti = MediaTypeIdentifier.load(ct)
        return mti if mti.handler_name == handler_name
      end

      # otherwise, pick the first
      pick = MediaTypeIdentifier.load(possible_values.first)

      # and return that one if it already corresponds to a registered handler
      # otherwise, add the encoding
      if Praxis::Application.instance.handlers.include?(pick.handler_name)
        return pick
      else
        return pick + handler_name
      end

    end
def derive_content_type(handler_name)
      possible_values = if self.content_type.match 'text/plain'
        _, content_type_attribute = self.headers_attribute && self.headers_attribute.attributes.find { |k,v| k.to_s =~ /^content[-_]{1}type$/i }
        if content_type_attribute && content_type_attribute.options.key?(:values)
          content_type_attribute.options[:values]
        else
          []
        end
      else
        [self.content_type]
      end

      # generic default encoding is the best we can do
      if possible_values.empty?
        return MediaTypeIdentifier.load("application/#{handler_name}")
      end

      # if any defined value match the preferred handler_name, return it
      possible_values.each do |ct|
        mti = MediaTypeIdentifier.load(ct)
        return mti if mti.handler_name == handler_name
      end

      # otherwise, pick the first
      pick = MediaTypeIdentifier.load(possible_values.first)

      # and return that one if it already corresponds to a registered handler
      # otherwise, add the encoding
      if Praxis::Application.instance.handlers.include?(pick.handler_name)
        return pick
      else
        return pick + handler_name
      end

    end
Determine an appropriate default content_type for this part given
 the preferred handler_name, if possible.

 Considers any pre-defined set of values on the content_type attributge
 of the headers.