Skip to content

Commit 38833c1

Browse files
committed
Mention the issues of ETag-based validation and Apache compression
1 parent 077ab13 commit 38833c1

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

http_cache/validation.rst

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ to implement the validation model: ``ETag`` and ``Last-Modified``.
3838
Validation with the ``ETag`` Header
3939
-----------------------------------
4040

41-
The ``ETag`` header is a string header (called the "entity-tag") that uniquely
42-
identifies one representation of the target resource. It's entirely generated
43-
and set by your application so that you can tell, for example, if the ``/about``
44-
resource that's stored by the cache is up-to-date with what your application
45-
would return. An ``ETag`` is like a fingerprint and is used to quickly compare
46-
if two different versions of a resource are equivalent. Like fingerprints,
47-
each ``ETag`` must be unique across all representations of the same resource.
41+
The ``ETag`` ("entity-tag") header is an optional HTTP header whose value is an
42+
arbitrary string that uniquely identifies one representation of the target
43+
resource. It's entirely generated and set by your application so that you can
44+
tell, for example, if the ``/about`` resource that's stored by the cache is
45+
up-to-date with what your application would return.
46+
47+
An ``ETag`` is like a fingerprint and is used to quickly compare if two
48+
different versions of a resource are equivalent. Like fingerprints, each
49+
``ETag`` must be unique across all representations of the same resource.
4850

4951
To see a simple implementation, generate the ETag as the md5 of the content::
5052

@@ -72,6 +74,21 @@ method compares the ``If-None-Match`` header with the ``ETag`` response header.
7274
If the two match, the method automatically sets the ``Response`` status code
7375
to 304.
7476

77+
.. note::
78+
79+
When using ``mod_deflate`` or ``mod_brotli`` in Apache 2.4, the original
80+
``ETag`` value is modified (e.g. if ``ETag`` was ``foo``, Apache turns it
81+
into ``foo-gzip`` or ``foo-brotli``), which breaks the ETag-based validation.
82+
83+
Starting from Apache 2.5, you can control this behavior with the
84+
``DeflateAlterETag`` and ``BrotliAlterETag`` directives. Alternatively, you
85+
can use the following Apache configuration to keep both the original ETag
86+
and the modified one when compressing responses:
87+
88+
.. code-block:: apache
89+
90+
RequestHeader edit "If-None-Match" '^"((.*)-(gzip|br))"$' '"$1", "$2"'
91+
7592
.. note::
7693

7794
The cache sets the ``If-None-Match`` header on the request to the ``ETag``

0 commit comments

Comments
 (0)