Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1111749 of Accept-Encoding

  • Revision slug: Web/HTTP/Headers/Accept-Encoding
  • Revision title: Accept-Encoding
  • Revision id: 1111749
  • Created:
  • Creator: fscholz
  • Is current revision? Yes
  • Comment fix github url

Revision Content

{{HTTPSidebar}}

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 {{HTTPHeader("Content-Encoding")}} response header.

Even if both the client and the server supports the same compression algorithms, the server may choose not to compress the body of a response, if the identity value is also acceptable. Two common cases lead to this:

  • The data to be sent is already compressed and a second compression won't lead to smaller data to be transmitted. This may the case with some image formats;
  • The server is overloaded and cannot afford the computational overhead induced by the compression requirement. Typically, Microsoft recommends not to compress if a server use more than 80 % of its computational power.

As long as the identity value, meaning no encryption, is not explicitly forbidden, by an identity;q=0 or a *;q=0 without another explicitly set value for identity, the server must never send back a {{HTTPStatus("406")}} Not Acceptable error.

Notes:
  • An IANA registry maintains a complete list of official content encodings.

  • Two others content encoding, bzip and bzip2, are sometimes used, though not standard. They implement the algorithm used by these two UNIX programs. Note that the first one was discontinued due to patent licensing problems.
Header type {{Glossary("Request header")}}
{{Glossary("Forbidden header name")}} yes

Syntax


Accept-Encoding: gzip
Accept-Encoding: compress
Accept-Encoding: deflate
Accept-Encoding: br
Accept-Encoding: identity
Accept-Encoding: *

// Multiple algorithms, weighted with the {{Glossary("Quality Values", "quality value")}} syntax:
Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5

Directives

gzip
A compression format using the Lempel-Ziv coding (LZ77), with a 32-bit CRC.
compress
A compression format using the Lempel-Ziv-Welch (LZW) algorithm.
deflate
A compression format using the zlib structure, with the deflate compression algorithm.
br
A compression format using the Brotli algorithm.
identity
Indicates the identity function (i.e. no compression, nor modification. This value is always considered as acceptable, even if not present.
*
Matches any content encoding not already listed in the header. This is the default value if the header is not present. It doesn't mean that any algorithm is supported; merely that no preference is expressed.
;q= (qvalues weighting)
Any value is placed in an order of preference expressed using a relative quality values called weight.

Examples


Accept-Encoding: gzip

Accept-Encoding: gzip, compress, br

Accept-Encoding: br;q=1.0, gzip;q=0.8, *;q=0.1

Specifications

Specification Title
{{RFC("7231", "Accept-Encoding", "5.3.4")}} Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context

Browser compatibility

{{Compat}}

See also

  • HTTP content negotiation
  • Header with the result of the content negotiation: {{HTTPHeader("Content-Encoding")}}
  • Other similar headers: {{HTTPHeader("TE")}}, {{HTTPHeader("Accept")}}, {{HTTPHeader("Accept-Charset")}}, {{HTTPHeader("Accept-Language")}}

Revision Source

<div>{{HTTPSidebar}}</div>

<p>The <strong><code>Accept-Encoding</code></strong> request HTTP header advertises which content encoding, usually a compression algorithm, the client is able to understand. Using <a href="/en-US/docs/Web/HTTP/Content_negotiation">content negotiation</a>, the server selects one of the proposals, uses it and informs the client of its choice with the {{HTTPHeader("Content-Encoding")}} response header.</p>

<p>Even if both the client and the server supports the same compression algorithms, the server may choose not to compress the body of a response, if the identity value is also acceptable. Two common cases lead to this:</p>

<ul>
 <li>The data to be sent is already compressed and a second compression won't lead to smaller data to be transmitted. This may the case with some image formats;</li>
 <li>The server is overloaded and cannot afford the computational overhead induced by the compression requirement. Typically, Microsoft recommends not to compress if a server use more than 80 % of its computational power.</li>
</ul>

<p>As long as the <code>identity</code> value, meaning no encryption, is not explicitly forbidden, by an <code>identity;q=0</code> or a <code>*;q=0</code> without another explicitly set value for identity, the server must never send back a {{HTTPStatus("406")}} <code>Not Acceptable</code> error.</p>

<div class="note"><strong>Notes:</strong>

<ul>
 <li>
  <p>An IANA registry maintains <a class="external" href="https://www.iana.org/assignments/http-parameters/http-parameters.xml#http-parameters-1" title="https://www.iana.org/assignments/http-parameters/http-parameters.xml#http-parameters-1">a complete list of official content encodings</a>.</p>
 </li>
 <li>Two others content encoding, <code>bzip</code> and <code>bzip2</code>, are sometimes used, though not standard. They implement the algorithm used by these two UNIX programs. Note that the first one was discontinued due to patent licensing problems.</li>
</ul>
</div>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Header type</th>
   <td>{{Glossary("Request header")}}</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Forbidden header name")}}</th>
   <td>yes</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">



Accept-Encoding: gzip
Accept-Encoding: compress
Accept-Encoding: deflate
Accept-Encoding: br
Accept-Encoding: identity
Accept-Encoding: *

// Multiple algorithms, weighted with the {{Glossary("Quality Values", "quality value")}} syntax:
Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5</pre>

<h2 id="Directives">Directives</h2>

<dl>
 <dt><code>gzip</code></dt>
 <dd>A compression format using the <a class="external external-icon" href="https://en.wikipedia.org/wiki/LZ77_and_LZ78#LZ77">Lempel-Ziv coding</a> (LZ77), with a 32-bit CRC.</dd>
 <dt><code>compress</code></dt>
 <dd>A compression format using the <a class="external external-icon" href="https://en.wikipedia.org/wiki/LZW">Lempel-Ziv-Welch</a> (LZW) algorithm.</dd>
 <dt><code>deflate</code></dt>
 <dd>A compression format using the <a class="external external-icon" href="https://en.wikipedia.org/wiki/Zlib">zlib</a> structure, with the <a class="external external-icon" href="https://en.wikipedia.org/wiki/DEFLATE"><em>deflate</em></a> compression algorithm.</dd>
 <dt><code>br</code></dt>
 <dd>A compression format using the <a class="external external-icon" href="https://en.wikipedia.org/wiki/Brotli">Brotli</a> algorithm.</dd>
 <dt><code>identity</code></dt>
 <dd>Indicates the identity function (i.e. no compression, nor modification. This value is always considered as acceptable, even if not present.</dd>
 <dt><code>*</code></dt>
 <dd>Matches any content encoding not already listed in the header. This is the default value if the header is not present. It doesn't mean that any algorithm is supported; merely that no preference is expressed.</dd>
 <dt><code>;q=</code> (qvalues weighting)</dt>
 <dd>Any value is placed in an order of preference expressed using a relative <a href="/en-US/docs/Glossary/Quality_value">quality values</a> called <em>weight</em>.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<pre>



Accept-Encoding: gzip

Accept-Encoding: gzip, compress, br

Accept-Encoding: br;q=1.0, gzip;q=0.8, *;q=0.1
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Title</th>
  </tr>
  <tr>
   <td>{{RFC("7231", "Accept-Encoding", "5.3.4")}}</td>
   <td>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

<p>{{Compat}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>HTTP <a href="/en-US/docs/Web/HTTP/Content_negotiation">content negotiation</a></li>
 <li>Header with the result of the content negotiation: {{HTTPHeader("Content-Encoding")}}</li>
 <li>Other similar headers: {{HTTPHeader("TE")}}, {{HTTPHeader("Accept")}}, {{HTTPHeader("Accept-Charset")}}, {{HTTPHeader("Accept-Language")}}</li>
</ul>
Revert to this revision