HTTP headers | Accept-Charset
The HTTP Accept-Charset is a request type header. This header is used to indicate what character set are acceptable for the response from the server. The accept-charset header specifies the character encodings which are accepted by the client and this header also allows a user-agent to specify the charsets it supports.
With the help of content negotiation it selects the type of encoding and then uses it to inform the client of its choice with the Content-Type response header, which is usually present in
charset= parameter. Our Web-Browser usually doesn’t send this header, as transmitting it would allow fingerprinting and the default value for each resource is usually correct. If this Header is not present, a user-agent would have to specify each charset parameter for each text/* media type it accepted, e.g.
Accept: text/html;charset=US-ASCII, text/html;charset=UTF-8, text/plain; charset=US-ASCII,text/plain;charset=UTF-8
Note: When the server fails to serve any character encoding form this request, it will send back a 406 Not Acceptable error code so to avoid this and provide better user experience if no Accept-Charset header is present, the default is that any character set is acceptable.
- This is the for single charset.
- This syntax works to select multiple character sets with quality value.
Accept-Charset: <charset>, <charset> ;q=
Directives: This header accepts three directives as mentioned above and described below:
- <charset>: This directive holds the charset type, any character encoding name, like UTF-32 ,UTF-16 or iso-8859-15.
- *: This directive is used as a wildcard for any character not mentioned in anywhere in header.
Note: This ;q= defines the factor weighting, value placed in an order of preference expressed using a relative quality value.
- In this example single value is on Accept-Charset header
- In this example double value is Accept-Charset header
Accept-Charset: utf-8, iso-8859-1;q=0.7
- In this example double value is Accept-Charset header with the second one using “ * “ wildcard to select all encodings
Accept-Charset: utf-8, iso-8859-1;q=0.7, *;q=0.9
Supported Browsers: The browsers are not compatible with HTTP Accept-Charset header.