406 Not Acceptable
The HTTP 406 status code means a server can’t return the requested version of the resource.
Clients can ask servers to serve a particular version of the resource (for example, HTML document, image file, JSON object).
For example, imagine a user has a Spanish locale set as the default (es-ES
). A browser can (and will) ask a server to provide a Spanish version of the website, if possible, but otherwise fall back to an English version.
Accept-Language: es-ES, es;q=1, en;q=0.5
This process is called content negotiation. Apart from language, clients can negotiate:
- Content types (MIME) via the
Accept
header. An image file can be encoded as JPEG or WebP, an API response can be returned as JSON or XML. - Encodings (think compression algorithms) via the
Accept-Encoding
header. The most common ones are gzip and brotli. - Charsets via the
Accept-Charset
header. Since UTF-8 support is ubiquitous, there’s little need to the point where most modern browsers don’t support it. Browsers omit this header to reduce entropy and preserve users’ privacy. - Client hints via the
Accept-CH
header. Client hints is a content negotiation mechanism where clients can proactively inform browsers about supported features. This is an experimental header.
HTTP spec states that browsers can respond with 406 Not Acceptable
when the server is unwilling to supply a default representation
; however, in reality, most servers do fall back to the default representation.