Accept-Encoding:gzip and Content-Encoding:gzip

26.7k views Asked by At

What is the difference between the two HTTP headers?

  • Accept-Encoding:gzip
  • Content-Encoding:gzip
2

There are 2 answers

0
Ratul Sharker On BEST ANSWER

Accept-Encoding:

It is a request header. The HTTP client uses this header to tell the server which encoding(s) it supports. The server is allowed to send the response content in any of these encodings.

From MDN

The Accept-Encoding request HTTP header advertises which content encoding, usually a compression algorithm, the client is able to understand. Using content negotiation, the server selects one of the proposals, uses it and informs the client of its choice with the Content-Encoding response header.

Content-Encoding:

It is a response header. The HTTP server uses this header to tell the client which particular encoding the content has actually been encoded in.

From MDN

The Content-Encoding entity header is used to compress the media-type. When present, its value indicates which encodings were applied to the entity-body. It lets the client know, how to decode in order to obtain the media-type referenced by the Content-Type header.

If you want to see them play in action, open Inspect Element in Firefox / Chrome, then check for the Network tab to see them in action. Look for Accept-Encoding in request headers and Content-Encoding in response headers.

Inspect Element in firefox

0
Rick-777 On

Accept-Encoding

To paraphrase IETF internet standard RFC-7231, the Accept-Encoding request header field can be used by user agents to make requests that indicate what response content-codings are acceptable in the response.

The Accept-Encoding header can be quite complex, e.g.

Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0

https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.4

Content-Encoding

The Content-Encoding response header field indicates what content codings have been applied to the response representation. Content-Encoding is primarily used to allow the response entity to be compressed without losing the identity of its underlying media type.

The Content-Encoding value is simple and should be accompanied by a "Vary" header, e.g.

Content-Encoding: gzip
Vary: Accept-Encoding

https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.2.2