﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
25044	[PATCH] Tile cache: If-Modified-Since sent with ETag defeats 304 responses and switches to HEAD requests	wangi	team	"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.
"	defect	new	normal		Core imagery			cache etag 304 If-Modified-Since If-None-Match mod_tile	
