What the Prefer header is for
The HTTP Prefer request header, defined in RFC 7240, lets a client express
optional preferences about how the server should handle a request. Crucially,
a preference is advisory: the server may apply it, partially apply it, or ignore
it entirely, and the request must still succeed either way. This makes Prefer
safe to send speculatively — you never break a request by asking for a behaviour
the server does not support.
How it works
A Prefer header carries one or more comma-separated preference tokens. Each
token is either a bare keyword (respond-async) or a name=value pair
(return=minimal, wait=10). Multiple preferences combine in one header:
Prefer: respond-async, wait=10, return=minimal
When the server honours a preference, it lists the applied tokens in a
Preference-Applied response header so the client can confirm what happened.
The registered tokens are respond-async, return (minimal or
representation), wait (seconds), and handling (strict or lenient).
Unknown tokens are simply ignored. The picker below assembles a syntactically
correct header from the tokens you select.
Tips and notes
A server that varies its behaviour on Prefer should generally not cache across
different preference values without care. Pair respond-async with wait to
bound how long the server may block before switching to an async 202 Accepted
response. Remember that absence of a token in Preference-Applied means the
preference was not applied — design your client to tolerate either outcome.