Opened 11 minutes ago
Last modified 7 minutes ago
#25044 new defect
[PATCH] Tile cache: If-Modified-Since sent with ETag defeats 304 responses and switches to HEAD requests
| Reported by: | wangi | Owned by: | team |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Core imagery | Version: | |
| Keywords: | cache etag 304 If-Modified-Since If-None-Match mod_tile | Cc: |
Description
When JOSM revalidates a cached tile it sends both If-None-Match (the ETag) and If-Modified-Since. The date in If-Modified-Since is not a Last-Modified received from the server, but the time JOSM downloaded the tile (JCSCachedTileLoaderJob.parseHeaders() sets lastModification to now).
Apache serving tiles with mod_tile, as many tile servers do, sends an ETag but no Last-Modified. Apache then takes the resource to be modified now, and it evaluates both conditions, so every If-Modified-Since older than the current second fails, and it answers 200 although the ETag matches. JOSM sees a 200 with the ETag it already has, logs "JCS - Host: ... found not to return 304 codes for If-Modified-Since or If-None-Match headers" (once per concurrent request), and verifies every tile of that host with a HEAD request first for the rest of the session.
Reproduction, against an Apache/mod_tile server:
U=https://tile.opengeofiction.net/ogf-carto/8/154/95.png
E=$(curl -s -D - -o /dev/null $U | grep -i '^etag' | cut -d' ' -f2- | tr -d '\r')
curl -s -o /dev/null -w '%{http_code}\n' -H "If-None-Match: $E" $U # 304
curl -s -o /dev/null -w '%{http_code}\n' -H "If-None-Match: $E" -H 'If-Modified-Since: Sun, 01 Nov 2026 12:00:00 GMT' $U # 200
RFC 9110 section 13.1.3 says a recipient must ignore If-Modified-Since when If-None-Match is present, so for a conforming server the extra header adds nothing. (The same section notes that a cache typically uses the cached Last-Modified as the date, which JOSM does not have here.)
The attached patch (against r19692) sends If-Modified-Since only when the cache entry has no ETag; with an ETag only If-None-Match is sent. Entries without an ETag are revalidated as before.
Unit tests:
testCheckUsingETagOnly: a server which answers 200 wheneverIf-Modified-Sinceis present and 304 to a matchingIf-None-Match; the cached tile is kept, and the request carries noIf-Modified-Since. It fails without the patch.testCheckUsingIfModifiedSinceWithoutETag: an entry without an ETag is still revalidated withIf-Modified-Since.
All tests in JCSCachedTileLoaderJobTest pass; checkstyle and PMD are clean. Also tested in a JOSM built with the patch.
Attachments (1)
Change History (2)
by , 11 minutes ago
| Attachment: | if-none-match-tiles.patch added |
|---|



Note that OpenGeofiction's tiles05 and tiles06 servers are behind a nginx proxy, which tile/tiles04 isn't, which strips
If-Modified-SincewhenIf-None-Matchis also set. Therefore they avoid this issue.