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

If-Range with a date is honoured for a weak Last-Modified (not a strong validator)

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

Defect

RFC 9110 §13.1.5: a server MUST ignore an If-Range that carries a date unless that date is a strong validator, i.e. the Last-Modified it is compared with is at least one second older than the response Date (§8.8.2.2). A Last-Modified closer than that to Date may still change within the same second, so a Range answered as 206 could stitch together bytes of two different versions of the representation.

Conditions.getRangeStatus(Tag, Date) only tests the equality of the two dates (DateUtils.equals(getRangeDate(), modificationDate), Conditions.java:249-253 in 3.0; same in 2.7 and 2.6). It never looks at the age of the modification date, so RangeFilter serves 206 for a resource modified less than a second ago. The tag branch is already correct (strong comparison, a weak tag never matches).

Observable behaviour: a resource whose Last-Modified is "now" (e.g. generated on the fly, or just written) and a client that sends Range: bytes=0-9 + If-Range: <that date>: the server answers 206; per the RFC it must answer 200 with the full entity.

Proposal

  • One shared "strong date" rule (modified is strong against reference if reference - modified >= 1 s), used by Conditions.unchangedSince (added with #100, same rule) and by getRangeStatus, with the current time as the reference on the server side (the Date header is written later, so it cannot be earlier). A weak date means If-Range is not satisfied, the range is ignored and the full 200 is sent (already what RangeFilter does on a failed condition).
  • 3.0, 2.7 and 2.6: same fix. No public API change; the behaviour changes only for the weak-date case, which the RFC forbids to serve as 206.

Not a defect: unparsable response Date

HeaderUtils replaces an unparsable Date response header by the time of reception. RFC 9110 §6.6.1 allows it (a recipient with a clock MAY replace an invalid Date with the time the response was received), so it stays. The only consequence, documented in the Javadoc of Conditions.unchangedSince, is that the strong-date deduction then relies on the client clock.

thboileau-git avatar Nov 28 '26 12:11 thboileau-git