Class PreferHeader
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 asynchandling=strict— reject requests with any issueshandling=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
HandlingStrict
Gets whether the client prefers handling=strict.
public bool HandlingStrict { get; }
Property Value
HasPreferences
Gets whether any recognized standard preference was specified in the request.
public bool HasPreferences { get; }
Property Value
RespondAsync
Gets whether the client prefers respond-async (asynchronous processing).
public bool RespondAsync { get; }
Property Value
ReturnMinimal
Gets whether the client prefers return=minimal (no body, typically 204).
public bool ReturnMinimal { get; }
Property Value
ReturnRepresentation
Gets whether the client prefers return=representation (full resource body).
public bool ReturnRepresentation { get; }
Property Value
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
requestHttpRequestThe HTTP request to read the
Preferheader from.
Returns
- PreferHeader
A PreferHeader representing the parsed preferences.