DefaultContentNegotiator DefaultContentNegotiator DefaultContentNegotiator Class

Definition

Class that selects a System.Net.Http.Formatting.MediaTypeFormatter for an HttpRequestMessage or HttpResponseMessage.

public class DefaultContentNegotiator : System.Net.Http.Formatting.IContentNegotiator
type DefaultContentNegotiator = class
    interface IContentNegotiator
Public Class DefaultContentNegotiator
Implements IContentNegotiator
Inheritance
DefaultContentNegotiatorDefaultContentNegotiatorDefaultContentNegotiator
Implements

Constructors

DefaultContentNegotiator() DefaultContentNegotiator() DefaultContentNegotiator()
DefaultContentNegotiator(Boolean) DefaultContentNegotiator(Boolean) DefaultContentNegotiator(Boolean)

Initializes a new instance of the DefaultContentNegotiator with the given setting for excludeMatchOnTypeOnly.

Properties

ExcludeMatchOnTypeOnly ExcludeMatchOnTypeOnly ExcludeMatchOnTypeOnly

If ExcludeMatchOnTypeOnly is true then we don't match on type only which means that we return null if we can't match on anything in the request. This is useful for generating 406 (Not Acceptable) status codes.

Methods

ComputeFormatterMatches(Type, HttpRequestMessage, IEnumerable<MediaTypeFormatter>) ComputeFormatterMatches(Type, HttpRequestMessage, IEnumerable<MediaTypeFormatter>) ComputeFormatterMatches(Type, HttpRequestMessage, IEnumerable<MediaTypeFormatter>)

Determine how well each formatter matches by associating a MediaTypeFormatterMatchRanking value with the formatter. Then associate the quality of the match based on q-factors and other parameters. The result of this method is a collection of the matches found categorized and assigned a quality value.

MatchAcceptHeader(IEnumerable<MediaTypeWithQualityHeaderValue>, MediaTypeFormatter) MatchAcceptHeader(IEnumerable<MediaTypeWithQualityHeaderValue>, MediaTypeFormatter) MatchAcceptHeader(IEnumerable<MediaTypeWithQualityHeaderValue>, MediaTypeFormatter)

Match the request accept header field values against the formatter's registered supported media types.

MatchMediaTypeMapping(HttpRequestMessage, MediaTypeFormatter) MatchMediaTypeMapping(HttpRequestMessage, MediaTypeFormatter) MatchMediaTypeMapping(HttpRequestMessage, MediaTypeFormatter)
MatchRequestMediaType(HttpRequestMessage, MediaTypeFormatter) MatchRequestMediaType(HttpRequestMessage, MediaTypeFormatter) MatchRequestMediaType(HttpRequestMessage, MediaTypeFormatter)

Match any request media type (in case there is a request entity body) against the formatter's registered media types.

MatchType(Type, MediaTypeFormatter) MatchType(Type, MediaTypeFormatter) MatchType(Type, MediaTypeFormatter)

Pick the first supported media type and indicate we've matched only on type

Negotiate(Type, HttpRequestMessage, IEnumerable<MediaTypeFormatter>) Negotiate(Type, HttpRequestMessage, IEnumerable<MediaTypeFormatter>) Negotiate(Type, HttpRequestMessage, IEnumerable<MediaTypeFormatter>)

Performs content negotiating by selecting the most appropriate System.Net.Http.Formatting.MediaTypeFormatter out of the passed in formatters for the given request that can serialize an object of the given type.

SelectResponseCharacterEncoding(HttpRequestMessage, MediaTypeFormatter) SelectResponseCharacterEncoding(HttpRequestMessage, MediaTypeFormatter) SelectResponseCharacterEncoding(HttpRequestMessage, MediaTypeFormatter)

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.

SelectResponseMediaTypeFormatter(ICollection<MediaTypeFormatterMatch>) SelectResponseMediaTypeFormatter(ICollection<MediaTypeFormatterMatch>) SelectResponseMediaTypeFormatter(ICollection<MediaTypeFormatterMatch>)

Select the best match among the candidate matches found.

ShouldMatchOnType(IEnumerable<MediaTypeWithQualityHeaderValue>) ShouldMatchOnType(IEnumerable<MediaTypeWithQualityHeaderValue>) ShouldMatchOnType(IEnumerable<MediaTypeWithQualityHeaderValue>)

Determine whether to match on type or not. This is used to determine whether to generate a 406 response or use the default media type formatter in case there is no match against anything in the request. If ExcludeMatchOnTypeOnly is true then we don't match on type unless there are no accept headers.

SortMediaTypeWithQualityHeaderValuesByQFactor(ICollection<MediaTypeWithQualityHeaderValue>) SortMediaTypeWithQualityHeaderValuesByQFactor(ICollection<MediaTypeWithQualityHeaderValue>) SortMediaTypeWithQualityHeaderValuesByQFactor(ICollection<MediaTypeWithQualityHeaderValue>)

Sort Accept header values and related header field values with similar syntax rules (if more than 1) in descending order based on q-factor.

SortStringWithQualityHeaderValuesByQFactor(ICollection<StringWithQualityHeaderValue>) SortStringWithQualityHeaderValuesByQFactor(ICollection<StringWithQualityHeaderValue>) SortStringWithQualityHeaderValuesByQFactor(ICollection<StringWithQualityHeaderValue>)

Sort Accept-Charset, Accept-Encoding, Accept-Language and related header field values with similar syntax rules (if more than 1) in descending order based on q-factor.

UpdateBestMatch(MediaTypeFormatterMatch, MediaTypeFormatterMatch) UpdateBestMatch(MediaTypeFormatterMatch, MediaTypeFormatterMatch) UpdateBestMatch(MediaTypeFormatterMatch, MediaTypeFormatterMatch)

Evaluates whether a match is better than the current match and if so returns the replacement; otherwise returns the current match.

Applies to