public SelectCharacterEncoding ( HttpRequestMessage contentHeaders ) : Encoding | ||
contentHeaders | HttpRequestMessage | The content headers provided as part of the request or response. |
리턴 | Encoding |
/// <summary> /// Determine the best character encoding for writing the response. First we look /// for accept-charset headers and if not found then we try to match /// any charset encoding in the request (in case of PUT, POST, etc.) /// If no encoding is found then we use the default for the formatter. /// </summary> /// <returns>The <see cref="Encoding"/> determined to be the best match.</returns> protected virtual Encoding SelectResponseCharacterEncoding(HttpRequestMessage request, MediaTypeFormatter formatter) { if (request == null) { throw Error.ArgumentNull("request"); } if (formatter == null) { throw Error.ArgumentNull("formatter"); } // If there are any SupportedEncodings then we pick an encoding if (formatter.SupportedEncodings.Count > 0) { // Sort Accept-Charset header values //IEnumerable<StringWithQualityHeaderValue> sortedAcceptCharsetValues = SortStringWithQualityHeaderValuesByQFactor(request.Headers.AcceptCharset); // TODO: Fix instead of using Formatter.SelectCharacterEncoding(); IEnumerable<StringWithQualityHeaderValue> sortedAcceptCharsetValues = Enumerable.Empty<StringWithQualityHeaderValue>(); // Check for match based on accept-charset headers foreach (StringWithQualityHeaderValue acceptCharset in sortedAcceptCharsetValues) { foreach (Encoding encoding in formatter.SupportedEncodings) { if (encoding != null && acceptCharset.Quality != FormattingUtilities.NoMatch && (acceptCharset.Value.Equals(encoding.WebName, StringComparison.OrdinalIgnoreCase) || acceptCharset.Value.Equals("*", StringComparison.OrdinalIgnoreCase))) { return encoding; } } } // Check for match based on any request entity body return formatter.SelectCharacterEncoding(request); } return null; }