/// <summary>Gets content type and encoding information from the headers if possible; defaults otherwise.</summary> /// <param name="accept">A comma-separated list of client-supported MIME Accept types.</param> /// <param name="acceptCharset">The specification for the character set encoding that the client requested.</param> /// <param name="contentType">After invocation, content type for the exception.</param> /// <param name="encoding">After invocation, encoding for the exception.</param> private static void TryGetResponseFormatForError(string accept, string acceptCharset, out string contentType, out Encoding encoding) { contentType = null; encoding = null; if (accept != null) { try { string[] availableTypes = new string[] { XmlConstants.MimeApplicationXml, XmlConstants.MimeApplicationJson }; contentType = HttpProcessUtility.SelectMimeType(accept, availableTypes); } catch (DataServiceException) { // Ignore formatting erros in Accept and rely on text. } } if (acceptCharset != null) { try { encoding = HttpProcessUtility.EncodingFromAcceptCharset(acceptCharset); } catch (DataServiceException) { // Ignore formatting erros in Accept-Charset and rely on text. } } contentType = contentType ?? XmlConstants.MimeApplicationXml; encoding = encoding ?? HttpProcessUtility.FallbackEncoding; }
internal static bool ResponseMediaTypeWouldBeJsonLight(string acceptTypesText, bool isEntityOrFeed) { string[] availableTypes = GetAvailableMediaTypesForV3WithJsonLight(isEntityOrFeed); string b = HttpProcessUtility.SelectMimeType(acceptTypesText, availableTypes); if (!string.Equals("application/json;odata=light", b, StringComparison.OrdinalIgnoreCase)) { return(string.Equals("application/json", b, StringComparison.OrdinalIgnoreCase)); } return(true); }
internal static string SelectResponseMediaType(string acceptTypesText, bool entityTarget, bool effectiveMaxResponseVersionIsLessThanThree) { string[] strArray; if (effectiveMaxResponseVersionIsLessThanThree) { strArray = GetAvailableMediaTypesForV2(entityTarget); } else { strArray = GetAvailableMediaTypesForV3WithoutJsonLight(entityTarget); } string str = HttpProcessUtility.SelectMimeType(acceptTypesText, strArray); if (CompareMimeType(str, "application/json")) { str = "application/json;odata=verbose"; } return(str); }