Пример #1
0
        public static IEnumerable <string> GetAcceptLanguageValues(this HttpRequest httpRequest)
        {
            var acceptLanguages = httpRequest.GetTypedHeaders().AcceptLanguage;

            if (acceptLanguages == default)
            {
                return(Enumerable.Empty <string>());
            }

            return(acceptLanguages?.Select(l => l.Value.ToString()));
        }
        /// <summary>
        /// Determines whether the specified request contains XML as indicated by a
        /// content type of either <c>application/xml</c>, <c>text/xml</c>, <c>application/xyz+xml</c>,
        /// or <c>text/xyz+xml</c>. The term <c>xyz</c> can for example be <c>rdf</c> or some other
        /// XML-derived media type.
        /// </summary>
        /// <returns>true if the specified request contains XML content; otherwise, false.</returns>
        /// <param name="request">The <see cref="HttpRequest"/> to check.</param>
        public static bool IsXml(this HttpRequest request)
        {
            var contentType = request?.GetTypedHeaders()?.ContentType;

            if (contentType == null)
            {
                return(false);
            }

            if (contentType.IsSubsetOf(ApplicationXmlMediaType) || contentType.IsSubsetOf(TextXmlMediaType))
            {
                return(true);
            }

            var type = contentType.Type;

            if (type.Equals("application", StringComparison.OrdinalIgnoreCase) ||
                type.Equals("text", StringComparison.OrdinalIgnoreCase))
            {
                return(contentType.SubType.EndsWith("+xml", StringComparison.OrdinalIgnoreCase));
            }

            return(false);
        }
Пример #3
0
 public static MediaTypeHeaderValue MediaTypeHeaderValue(this HttpRequest httpRequest) => httpRequest.GetTypedHeaders().ContentType;