Table of Contents

Class PreferHeader

Namespace
Trellis.Asp
Assembly
Trellis.Asp.dll

Parses the RFC 7240 Prefer request header and exposes standard preference tokens.

public sealed class PreferHeader
Inheritance
PreferHeader
Inherited Members
Extension Methods

Examples

var prefer = PreferHeader.Parse(httpContext.Request);
if (prefer.ReturnMinimal)
    return Results.NoContent();

Remarks

The Prefer header allows clients to request optional server behaviors:

  • return=representation — return the full resource after a write (200 OK)
  • return=minimal — return a minimal response after a write (204 No Content)
  • respond-async — prefer asynchronous processing (202 Accepted)
  • wait=N — maximum seconds the client will wait before preferring async
  • handling=strict — reject requests with any issues
  • handling=lenient — process requests despite minor issues

Per RFC 7240 §2, unrecognized or malformed preference tokens are silently ignored. If a preference appears more than once, the first recognized (valid) occurrence is honored.

Properties

HandlingLenient

Gets whether the client prefers handling=lenient.

public bool HandlingLenient { get; }

Property Value

bool

HandlingStrict

Gets whether the client prefers handling=strict.

public bool HandlingStrict { get; }

Property Value

bool

HasPreferences

Gets whether any recognized standard preference was specified in the request.

public bool HasPreferences { get; }

Property Value

bool

RespondAsync

Gets whether the client prefers respond-async (asynchronous processing).

public bool RespondAsync { get; }

Property Value

bool

ReturnMinimal

Gets whether the client prefers return=minimal (no body, typically 204).

public bool ReturnMinimal { get; }

Property Value

bool

ReturnRepresentation

Gets whether the client prefers return=representation (full resource body).

public bool ReturnRepresentation { get; }

Property Value

bool

Wait

Gets the wait=N preference value in seconds, or null if not specified.

public int? Wait { get; }

Property Value

int?

Methods

Parse(HttpRequest)

Parses the Prefer header from the given HTTP request. Returns an empty PreferHeader if the header is absent or empty.

public static PreferHeader Parse(HttpRequest request)

Parameters

request HttpRequest

The HTTP request to read the Prefer header from.

Returns

PreferHeader

A PreferHeader representing the parsed preferences.