Skip to main content

fresh

Function fresh 

Source
pub fn fresh(req: &Request<'_>, res: &Response<'_>) -> bool
Expand description

Returns true if the response is fresh for this request — meaning the server may answer 304 Not Modified rather than resending the body.

The check mirrors the npm fresh package:

  1. An unconditional request (no If-None-Match and no If-Modified-Since) is never fresh.
  2. Cache-Control: no-cache always forces stale.
  3. If If-None-Match is present and not *, the response ETag must match one of its entries (with weak/strong W/ comparison).
  4. If If-Modified-Since is present, the response Last-Modified must be no newer than it.

Empty-string headers are treated as absent.

use http_fresh::{fresh, Request, Response};

let req = Request::new().if_modified_since("Sun, 06 Nov 1994 08:49:37 GMT");
let res = Response::new().last_modified("Sat, 05 Nov 1994 08:49:37 GMT");
assert!(fresh(&req, &res)); // not modified since → fresh