The HTTP Accept-Encoding request header is included in an HTTP message to indicate the types of content encoding that the client can understand. This normally refers to Compression algorithms.
The HTTP Accept-Encoding request header is part of the Content Negotiation process and specifies which encoding methods are supported by the client. The server will choose one of the available methods and then inform the client of the selection by including the Content-Encoding header in the HTTP response.
In some cases, even where the client and server support the same encoding methods, there is no manipulation of the original resource before sending it. This can occur in situations where the identity value of the resource is also acceptable. One common example of this is when the data is already compressed, and applying a subsequent Compression algorithm will not further reduce the size. This happens with pre-compressed image files, such as JPEG. Another situation is where the server is heavily loaded and can’t spare the resources required to manipulate the data pre-transmission.
Multiple encodings can be specified using separate HTTP Accept-Encoding headers, or instead, by using a comma-delimited list. The q-factor can also be included to indicate a preference or priority.
In this example, the client requests that the server uses one of several encoding methods. In the first variation, each of the options is given equal priority. In the second variation, the q-value directive is used to assign weight to the encoding priority. The server responds with the list of encodings that were applied, ordered in the way that they were processed.
Request (variation #1)
GET / HTTP/1.1 Host: www.example.ai Accept-Encoding: gzip Accept-Encoding: deflate Accept-Encoding: br Accept-Encoding: identity Accept-Encoding: *
Request (variation #2)
GET / HTTP/1.1 Host: www.example.ai Accept-Encoding: gzip, deflate, br;q=1.0, identity;q=0.5, *;q=0.25
HTTP/1.1 200 OK Content-Encoding: gzip, br
The HTTP Accept-Encoding request header is used by clients to inform the server which encoding methods they can understand. When supported and advantageous to do so, the server will apply the encoding algorithm(s) and inform the client appropriately.