Expand description
103 Early Hints (RFC 8297, 18.12.0, #38): Link headers a client can
act on — preload a stylesheet, preconnect to an origin — while the
response is still being made.
A handler or middleware calls send at any point before it returns;
the connection writes a 103 head straight away and the final response
after it. EarlyHintsLayer sends a fixed list for every request it
sees:
use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::early_hints::EarlyHintsLayer;
let app = App::new().wrap(EarlyHintsLayer::new([
"</app.css>; rel=preload; as=style",
"<https://cdn.example.com>; rel=preconnect",
]));Sent on HTTP/2 and HTTP/3; on HTTP/1.1 only with
RWS_CONFIG_EARLY_HINTS_HTTP1=true (browsers use them only over h2/h3,
and some old HTTP/1.1 clients mishandle extra 1xx responses), never on
HTTP/1.0. The http1-only build writes them just before the final
response. Where nothing can send them — TestClient,
an app called directly — send does nothing and returns false.
At most MAX_PER_REQUEST per request; a value with CR, LF or NUL is
refused.
Structs§
- Early
Hints Layer - Middleware that sends the same
Linkhints for every request, then hands it on.
Constants§
- MAX_
PER_ REQUEST 103heads one request may send.
Functions§
- available
- Whether
sendwould reach a client from here. - send
- Send a
103 Early Hintswith theseLinkheader values now, before the final response.falsewhen there is nowhere to send it (see the module docs), the request already sentMAX_PER_REQUEST, or a value is empty or holds CR, LF or NUL. - valid
- A usable
Linkvalue: not empty, no CR, LF or NUL.