internal static Encoding GetEncoding2(string contentType) { // default to old text/* behavior for non-application base if (!ContentType.IsApplication(contentType)) { return(GetEncoding(contentType)); } string charset = ContentType.GetCharset(contentType); Encoding e = null; try { if (charset != null && charset.Length > 0) { e = Encoding.GetEncoding(charset); } } catch (Exception ex) { if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException) { throw; } if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RequestResponseUtils), "GetEncoding2", ex); } } // no default per application/* mime type return(e); }
/* * internal static string UTF8StreamToString(Stream stream) { * long position = 0; * if (stream.CanSeek) * position = stream.Position; * StreamReader reader = new StreamReader(stream, new System.Text.UTF8Encoding()); * string result = reader.ReadToEnd(); * if (stream.CanSeek) * stream.Position = position; * return result; * } */ // internal static Encoding GetEncoding(string contentType) { string charset = ContentType.GetCharset(contentType); Encoding e = null; try { if (charset != null && charset.Length > 0) { e = Encoding.GetEncoding(charset); } } catch (Exception ex) { if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException) { throw; } if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RequestResponseUtils), "GetEncoding", ex); } } // default to ASCII encoding per RFC 2376/3023 return(e == null ? new ASCIIEncoding() : e); }
internal static Encoding GetEncoding2(string contentType) { if (!ContentType.IsApplication(contentType)) { return(GetEncoding(contentType)); } string charset = ContentType.GetCharset(contentType); Encoding encoding = null; try { if ((charset != null) && (charset.Length > 0)) { encoding = Encoding.GetEncoding(charset); } } catch (Exception exception) { if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException)) { throw; } if (Tracing.On) { Tracing.ExceptionCatch(TraceEventType.Warning, typeof(RequestResponseUtils), "GetEncoding2", exception); } } return(encoding); }
/* * internal static string UTF8StreamToString(Stream stream) { * long position = 0; * if (stream.CanSeek) * position = stream.Position; * StreamReader reader = new StreamReader(stream, new System.Text.UTF8Encoding()); * string result = reader.ReadToEnd(); * if (stream.CanSeek) * stream.Position = position; * return result; * } */ // CONSIDER, alexdej: GetEncoding and GetEncoding2 should be merged at some point // since GetEncoding2 handles application/* correctly internal static Encoding GetEncoding(string contentType) { string charset = ContentType.GetCharset(contentType); Encoding e = null; try { if (charset != null && charset.Length > 0) { e = Encoding.GetEncoding(charset); } } catch (Exception) { } // default to ASCII encoding per RFC 2376/3023 return(e == null ? new ASCIIEncoding() : e); }
internal static Encoding GetEncoding2(string contentType) { // default to old text/* behavior for non-application base if (!ContentType.MatchesBase(contentType, ContentType.ApplicationBase)) { return(GetEncoding(contentType)); } string charset = ContentType.GetCharset(contentType); Encoding e = null; try { if (charset != null && charset.Length > 0) { e = Encoding.GetEncoding(charset); } } catch (Exception) { } // no default per application/* mime type return(e); }