restlet-framework-java icon indicating copy to clipboard operation
restlet-framework-java copied to clipboard

A 304 (Not Modified) response omits the Expires header

Open thboileau-git opened this issue 1 week ago • 0 comments

Problem

RFC 9110 §15.4.5: a server generating a 304 response MUST generate the header fields that would have been sent in a 200 response to the same request: Content-Location, Date, ETag and Vary, and also Cache-Control and Expires (RFC 9111), so that the cache can refresh the stored response.

Restlet only copies ETag and Content-Location from the entity (HeaderUtils.addNotModifiedEntityHeaders), so Expires is dropped. Measured on 3.0 with a resource that sets a tag, a modification date, an expiration date, a location, a max-age directive and a Vary dimension:

GET /r                          -> 200: Content-Location, Content-Type, Expires, Last-Modified, ETag, Cache-Control, Date, Vary
GET /r  If-None-Match: "v1"     -> 304: ETag, Content-Location, Cache-Control, Date, Vary     (no Expires)

A cache that revalidates therefore keeps the old Expires of its stored response, and an entity whose expiration date was moved is not refreshed by the 304.

The same method (addNotModifiedEntityHeaders) is used by the Netty server call in 3.0 and by ServerAdapter in 2.7 and 2.6 (Jetty, Simple, ...), so the three maintained versions are affected.

Proposal

Write Expires (when the entity has an expiration date) in addNotModifiedEntityHeaders, in 3.0, 2.7 and 2.6. No API change.

thboileau-git avatar Nov 26 '26 20:11 thboileau-git