Skip to main content

Module early_hints

Module early_hints 

Source
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§

EarlyHintsLayer
Middleware that sends the same Link hints for every request, then hands it on.

Constants§

MAX_PER_REQUEST
103 heads one request may send.

Functions§

available
Whether send would reach a client from here.
send
Send a 103 Early Hints with these Link header values now, before the final response. false when there is nowhere to send it (see the module docs), the request already sent MAX_PER_REQUEST, or a value is empty or holds CR, LF or NUL.
valid
A usable Link value: not empty, no CR, LF or NUL.