Beispiel #1
0
        /// <summary>
        ///     Registers a content handler to process response content
        /// </summary>
        /// <param name="contentType">MIME content type of the response content</param>
        /// <param name="deserializer">Deserializer to use to process content</param>
        public void AddHandler(string contentType, IDeserializer deserializer)
        {
            ContentHandlers[contentType] = deserializer;

            if (contentType == "*" || IsWildcardStructuredSuffixSyntax(contentType))
            {
                return;
            }

            if (!AcceptTypes.Contains(contentType))
            {
                AcceptTypes.Add(contentType);
            }

            // add Accept header based on registered deserializers
            var accepts = string.Join(", ", AcceptTypes.ToArray());

            this.RemoveDefaultParameter("Accept");
            this.AddDefaultParameter("Accept", accepts, ParameterType.HttpHeader);
        }
Beispiel #2
0
        public string SelectFirstMatching(IEnumerable <string> candidates)
        {
            var exact = candidates.FirstOrDefault(x => AcceptTypes.Contains(x));

            return(exact ?? (AcceptsAny() ? candidates.FirstOrDefault() : null));
        }
Beispiel #3
0
 public bool AcceptsAny()
 {
     return(AcceptTypes.Contains("*/*"));
 }
Beispiel #4
0
 public bool AcceptsHtml()
 {
     return(AcceptTypes.Contains(MimeType.Html.ToString()));
 }
Beispiel #5
0
 public bool CanConvert(FileConverterContext context)
 {
     return(TargetType == context.TargetType &&
            AcceptTypes.Contains(context.InputType));
 }