Table of Contents

Class ConfigurableResponseNegotiator<TOptions>

Namespace
Codebelt.Extensions.Carter.Response
Assembly
Codebelt.Extensions.Carter.dll

Provides an abstract, configurable base class for Carter response negotiators that serialize models using a StreamFormatter<TOptions>.

public abstract class ConfigurableResponseNegotiator<TOptions> : Configurable<TOptions>, IConfigurable<TOptions>, IResponseNegotiator where TOptions : class, IExceptionDescriptorOptions, IContentNegotiation, IValidatableParameterObject, new()

Type Parameters

TOptions

The type of the configured options.

Inheritance
Configurable<TOptions>
ConfigurableResponseNegotiator<TOptions>
Implements
IConfigurable<TOptions>
Derived
Inherited Members

Constructors

ConfigurableResponseNegotiator(TOptions)

Initializes a new instance of the ConfigurableResponseNegotiator<TOptions> class.

protected ConfigurableResponseNegotiator(TOptions options)

Parameters

options TOptions

The TOptions used to configure content negotiation and serialization behavior.

Properties

ContentType

Gets the matched content type determined by the most recent successful call to CanHandle(MediaTypeHeaderValue).

public string ContentType { get; }

Property Value

string

The matched content type media type string, or null if CanHandle(MediaTypeHeaderValue) has not yet been called successfully.

Methods

CanHandle(MediaTypeHeaderValue)

Determines whether this negotiator can handle the specified accept media type.

public virtual bool CanHandle(MediaTypeHeaderValue accept)

Parameters

accept MediaTypeHeaderValue

The MediaTypeHeaderValue from the HTTP request's Accept header.

Returns

bool

true if the negotiator can handle the specified media type; otherwise, false.

GetDefaultEncoding()

When overridden in a derived class, returns the default character encoding for this negotiator. This encoding is used as the fallback by GetEncoding(HttpRequest) when the HTTP request does not specify a resolvable Accept-Charset preference.

protected abstract Encoding GetDefaultEncoding()

Returns

Encoding

The default Encoding for this negotiator.

GetEncoding(HttpRequest)

Resolves the character encoding for the HTTP response by inspecting the Accept-Charset header of the request, falling back to GetDefaultEncoding() when no valid charset is indicated.

public virtual Encoding GetEncoding(HttpRequest request)

Parameters

request HttpRequest

The current HttpRequest.

Returns

Encoding

The Encoding to use when writing the response body.

GetFormatter()

When overridden in a derived class, returns the StreamFormatter<TOptions> used to serialize the response model.

public abstract StreamFormatter<TOptions> GetFormatter()

Returns

StreamFormatter<TOptions>

A StreamFormatter<TOptions> configured with the current TOptions.

Handle<T>(HttpRequest, HttpResponse, T, CancellationToken)

Serializes the specified model and writes it to the HTTP response body.

public virtual Task Handle<T>(HttpRequest req, HttpResponse res, T model, CancellationToken cancellationToken)

Parameters

req HttpRequest

The current HttpRequest.

res HttpResponse

The current HttpResponse to which the serialized content is written.

model T

The model to serialize.

cancellationToken CancellationToken

A CancellationToken used to propagate notification that the operation should be canceled.

Returns

Task

A Task that represents the asynchronous write operation.

Type Parameters

T

The type of the model to serialize.

See Also