Skip to main content

Module etag

Module etag 

Source
Expand description

Entity tags and conditional requests.

A client that polls GET /api/orders every few seconds is, most of the time, downloading a body identical to the one it already has. With this middleware the response carries an ETag; the client sends it back as If-None-Match; and when nothing has changed the answer is a 304 Not Modified with no body at all. The handler still runs — this is a bandwidth saving, not a compute saving — but the bytes stay home.

App::new()?.middleware(ETag::default())

A handler that sets its own ETag or Last-Modified is left alone, and its validators are honoured. Both If-None-Match and If-Modified-Since are evaluated with the precedence RFC 9110 §13.2.2 gives them: when the client sends both, only the tag counts.

Structs§

ETag

Functions§

etag_for
A validator for a body: hex length, a dash, and a 64-bit hash.