Modify ↓

Opened 28 minutes ago

Last modified 24 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 whenever If-Modified-Since is present and 304 to a matching If-None-Match; the cached tile is kept, and the request carries no If-Modified-Since. It fails without the patch.
  • testCheckUsingIfModifiedSinceWithoutETag: an entry without an ETag is still revalidated with If-Modified-Since.

All tests in JCSCachedTileLoaderJobTest pass; checkstyle and PMD are clean. Also tested in a JOSM built with the patch.

Attachments (1)

if-none-match-tiles.patch​ (6.6 KB ) - added by wangi 27 minutes ago.

Download all attachments as: .zip

Change History (2)

by wangi, 27 minutes ago

Attachment: if-none-match-tiles.patch​ added

comment:1 by wangi, 24 minutes ago

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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain team.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from team to the specified user.
Next status will be 'needinfo'. The owner will be changed from team to wangi.
as duplicate The resolution will be set to duplicate. Next status will be 'closed'. The specified ticket will be cross-referenced with this ticket.
The owner will be changed from team to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.