Esempio n. 1
0
        /// <summary>
        /// Finds an IDataReader by content-type header
        /// </summary>
        /// <param name="contentTypeHeader"></param>
        /// <returns></returns>
        public virtual IDataReader Find(string contentTypeHeader)
        {
            // TODO: implement this negotiation
            // http://jsr311.java.net/nonav/releases/1.1/spec/spec3.html#x3-380003.8

            string type = DataProviderUtility.ParseMediaType(contentTypeHeader);

            IDataReader reader;

            if (this.ReadersByMime.TryGetValue(type, out reader))
            {
                return(reader);
            }

            return(null);
        }
        /// <summary>
        /// Parses HTTP headers for Media-Types
        /// </summary>
        /// <param name="accept">HTTP Accept header</param>
        /// <param name="contentType">HTTP Content-Type header</param>
        /// <returns>sequence of Media-Types</returns>
        /// <remarks>
        /// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
        /// </remarks>
        public static IEnumerable <string> ParseHeaders(string accept, string contentType)
        {
            string mime;

            // check for a matching accept type
            foreach (string type in DataProviderUtility.SplitTrim(accept, ','))
            {
                mime = DataProviderUtility.ParseMediaType(type);
                if (!String.IsNullOrEmpty(mime))
                {
                    yield return(mime);
                }
            }

            // fallback on content-type
            mime = DataProviderUtility.ParseMediaType(contentType);
            if (!String.IsNullOrEmpty(mime))
            {
                yield return(mime);
            }
        }