pub fn fresh(req: &Request<'_>, res: &Response<'_>) -> boolExpand 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:
- An unconditional request (no
If-None-Matchand noIf-Modified-Since) is never fresh. Cache-Control: no-cachealways forces stale.- If
If-None-Matchis present and not*, the responseETagmust match one of its entries (with weak/strongW/comparison). - If
If-Modified-Sinceis present, the responseLast-Modifiedmust 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