/// <summary> /// /// </summary> /// <param name="type"></param> /// <returns></returns> public static string ParseMediaType(string type) { foreach (string mime in DataWriterProvider.SplitTrim(type, ';')) { // only return first part return(mime); } // if no parts then was empty return(String.Empty); }
/// <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 DataWriterProvider.SplitTrim(accept, ',')) { mime = DataWriterProvider.ParseMediaType(type); if (!String.IsNullOrEmpty(mime)) { yield return(mime); } } // fallback on content-type mime = DataWriterProvider.ParseMediaType(contentType); if (!String.IsNullOrEmpty(mime)) { yield return(mime); } }