Syndicator Blog

HTTP

A Gzip Suffix on the ETag Keeps 29 WordPress Feeds From Answering 304 Not Modified

Syndicator pulls 31 WordPress feeds from sites in its network. Two of them (analysis.org and cybersecuritymarket.com) couldn't be reached from the test machine on December 2. Each of the other 29 got the conditional request a careful feed reader sends, with both the stored ETag and the stored Last-Modified date. None of them answered 304 Not Modified. Every one sent the full feed back.

The requests went out with curl at about 09:25 UTC, and the main result was checked again with Python's feedparser 6.0.14. Everything below covers those 29 feeds.

The conditional GET post on this blog told feed clients to store both validators and send both back. On these feeds, that advice gets you nothing.

What the 29 feeds send

The headers were the same on every feed:

HeaderValue on all 29
servercloudflare
content-typeapplication/rss+xml; charset=UTF-8
last-modifiedpresent
etagpresent, ending in -gzip
cache-controlmax-age=172800
cf-cache-statusDYNAMIC

All 29 report WordPress 7.1.5 in the feed's generator element. Feeds run from 76,730 to 111,336 bytes, with a median of 95,102. Gzip brings the median down to 24,147 bytes. Most carry 100 items, summaries only, with no content:encoded.

Four requests, four answers

Each feed got the same set of requests, using the validators from its own first response:

Request headersResult on 29 feeds
none200
If-Modified-Since only304
If-None-Match only200
both200

feedparser does what a reader should. Calling feedparser.parse(url, etag=..., modified=...) on pxef.com sent both headers and came back with status 200 and all 100 entries. The same call with only modified came back 304 with no entries.

The 200 responses even carried the exact ETag the client had just sent. The server hands out a validator it can't match.

Where the suffix comes from

Here is the ETag pxef.com sends when the client accepts gzip:

etag: "157bf0dfc40dd4c601ba3aa52639df5b-gzip"

Without Accept-Encoding: gzip, the same feed comes back uncompressed with W/"157bf0dfc40dd4c601ba3aa52639df5b-gzip". That fits the Cloudflare ETag docs, which describe Cloudflare decompressing a gzip response for a visitor and returning it with a weak ETag.

WordPress builds the feed ETag itself, in WP::send_headers:

$wp_etag           = '"' . md5( $wp_last_modified ) . '"';

$wp_last_modified is the date string WordPress puts in the Last-Modified header. On all 29 feeds, the hex part of the ETag equals the MD5 of that feed's Last-Modified value. So WordPress produced "157bf0dfc40dd4c601ba3aa52639df5b", and something between WordPress and the reader added -gzip.

Then comes the test for a 304, from the same function:

if ( ( $client_last_modified && $client_etag )
? ( ( $client_modified_timestamp >= $wp_modified_timestamp ) && ( $client_etag === $wp_etag ) )
: ( ( $client_modified_timestamp >= $wp_modified_timestamp ) || ( $client_etag === $wp_etag ) )

When a client sends both headers, both have to match, and the ETag check is an exact string comparison. The suffixed value never equals WordPress's own. The date matches, the ETag doesn't, and the answer is 200. Send the date alone and the second branch applies, so the date is enough.

Stripping the suffix proves it. On the six feeds tried, If-None-Match: "157bf0dfc40dd4c601ba3aa52639df5b" (the bare hash) got a 304, alone or together with the date. The weak form of the bare hash also got a 304, so something on the way in appears to remove the W/ prefix. Nothing removes -gzip.

The likely source is Apache's mod_deflate. Its DeflateAlterETag directive defaults to AddSuffix, which appends the compression method to the ETag, and the Apache docs say plainly that this "prevents serving 'HTTP Not Modified' (304) responses to conditional requests for compressed content." The headers don't name the origin server (the only server value is cloudflare), so treat this as the probable cause. It isn't confirmed. It's also new. The November 14 post quoted pxef.com's ETag with no suffix, and a 304 worked then.

WordPress's rule of requiring both matches makes no difference here. The HTTP spec (RFC 7232, now replaced by RFC 9110) says a server "MUST ignore If-Modified-Since if the request contains an If-None-Match header field." A server that follows the spec to the letter would also answer 200 here, because the ETag is the only thing it would look at. Either way, the suffix decides the outcome.

What it costs

One full round of all 29 feeds came to 677,064 bytes with gzip and 2,792,080 bytes without. A 304 body is zero bytes. A reader polling hourly with both headers pulls about 16 MB a day from these 29 feeds with gzip. On a quiet hour, every byte of that is a copy the reader already has. At 09:25 UTC, only 9 of the 29 had a Last-Modified date from that day, and the oldest was October 31.

A two-day max-age on hourly feeds

The other odd header is cache-control: max-age=172800, with an expires date two days out. The feeds themselves say <sy:updatePeriod>hourly</sy:updatePeriod>. A client that honors max-age, which is also standard advice, would wait 48 hours between checks and show new posts up to two days late. A feed that changes several times a day should advertise a much shorter lifetime than that.

Checking a feed and fixing it

This script prints the status for both headers together and for the date alone. Swap in your own feed URL:

FEED=https://pxef.com/feed/
H=$(curl -s -D - -o /dev/null -H 'Accept-Encoding: gzip' "$FEED")
ETAG=$(printf '%s' "$H" | grep -i '^etag:' | cut -d' ' -f2- | tr -d '\r')
LM=$(printf '%s' "$H" | grep -i '^last-modified:' | cut -d' ' -f2- | tr -d '\r')
echo "ETag: $ETAG"
echo "Last-Modified: $LM"
curl -s -o /dev/null -w 'both: %{http_code}\n' \
  -H "If-None-Match: $ETAG" -H "If-Modified-Since: $LM" "$FEED"
curl -s -o /dev/null -w 'date only: %{http_code}\n' \
  -H "If-Modified-Since: $LM" "$FEED"

On pxef.com it printed both: 200 and date only: 304. A healthy feed prints 304 twice, as long as nothing was published between the two requests.

If your origin runs Apache 2.4.58 or later, the docs list two other settings. DeflateAlterETag NoChange leaves WordPress's hash alone so it matches again, though the docs note this breaks the rule that each representation gets its own ETag. DeflateAlterETag Remove drops the ETag from compressed responses, which leaves Last-Modified to do the job, and that path already works. We haven't tested either change on these sites. On other servers, find whichever layer compresses the response and check what it does to ETags.

Feed reader and aggregator authors can't fix servers, but they can work around this one. Keep sending both headers, because that's what the spec asks for. If a 200 comes back carrying the same ETag you just sent, the server can't match its own validator. Drop If-None-Match for that feed and send only If-Modified-Since from then on. On all 29 of these feeds, that change turns every quiet poll into a 304.

Syndicator itself doesn't send conditional headers yet. It keeps each feed body in a 45-minute disk cache and rebuilds every 12 hours. When it gets conditional requests, it'll need this fallback, or its WordPress sources will keep sending full feeds.