示例#1
0
        internal static IList <KeyValuePair <string, string> > ReadMimeType(string contentType, out string mediaTypeName, out string mediaTypeCharset)
        {
            if (string.IsNullOrEmpty(contentType))
            {
                throw new ODataException(Strings.HttpUtils_ContentTypeMissing);
            }
            IList <KeyValuePair <MediaType, string> > list = ReadMediaTypes(contentType);

            if (list.Count != 1)
            {
                throw new ODataException(Strings.HttpUtils_NoOrMoreThanOneContentTypeSpecified(contentType));
            }
            KeyValuePair <MediaType, string> pair = list[0];
            MediaType key = pair.Key;

            MediaTypeUtils.CheckMediaTypeForWildCards(key);
            mediaTypeName = key.FullTypeName;
            KeyValuePair <MediaType, string> pair2 = list[0];

            mediaTypeCharset = pair2.Value;
            return(key.Parameters);
        }
示例#2
0
        /// <summary>Reads a Content-Type header and extracts the media type's name (type/subtype) and parameters.</summary>
        /// <param name="contentType">The Content-Type header.</param>
        /// <param name="mediaTypeName">The media type in standard type/subtype form, without parameters.</param>
        /// <param name="mediaTypeCharset">The (optional) charset parameter of the media type.</param>
        /// <returns>The parameters of the media type not including the 'charset' parameter.</returns>
        internal static IList <KeyValuePair <string, string> > ReadMimeType(string contentType, out string mediaTypeName, out string mediaTypeCharset)
        {
            DebugUtils.CheckNoExternalCallers();
            if (String.IsNullOrEmpty(contentType))
            {
                throw new ODataException(Strings.HttpUtils_ContentTypeMissing);
            }

            IList <KeyValuePair <MediaType, string> > mediaTypes = ReadMediaTypes(contentType);

            if (mediaTypes.Count != 1)
            {
                throw new ODataException(Strings.HttpUtils_NoOrMoreThanOneContentTypeSpecified(contentType));
            }

            MediaType mediaType = mediaTypes[0].Key;

            MediaTypeUtils.CheckMediaTypeForWildCards(mediaType);

            mediaTypeName    = mediaType.FullTypeName;
            mediaTypeCharset = mediaTypes[0].Value;

            return(mediaType.Parameters);
        }