pub enum ReplyData {
Json(Value),
Bytes {
content_type: Cow<'static, str>,
data: Vec<u8>,
},
Empty,
Rich(Box<ReplySpec>),
Stream(BodyStream),
Upgrade(Box<dyn Any + Send>),
}Expand description
Variants§
Json(Value)
A JSON body (Content-Type: application/json).
Bytes
Raw bytes plus the Content-Type to send. There is no default —
callers pick the type at the call site (application/zip,
image/png, application/octet-stream, …). Construct via
bytes(). The finalizer emits the header verbatim.
Fields
Empty
An empty body — 204 No Content by default.
Rich(Box<ReplySpec>)
A reply carrying explicit status / headers (a ReplySpec) on top of
one of the other payload kinds.
Stream(BodyStream)
A streaming body, written out as the stream yields.
Upgrade(Box<dyn Any + Send>)
An HTTP connection-upgrade reply (e.g. WebSocket). Produced by
actus::ws::upgrade(...) (with the websocket feature) and consumed
by the server, which completes the handshake (101 Switching Protocols)
and then hands the upgraded connection to the handler. The boxed value
is opaque server plumbing — don’t construct or inspect it directly.
Implementations§
Source§impl ReplyData
impl ReplyData
Sourcepub fn add_header(&mut self, name: impl Into<String>, value: impl Into<String>)
pub fn add_header(&mut self, name: impl Into<String>, value: impl Into<String>)
Add a response header, replacing any header already on the reply
whose name matches case-insensitively — HTTP field names are
case-insensitive (RFC 9110 §5.1), so add_header("cache-control", …)
replaces a handler’s "Cache-Control" rather than sitting beside it.
Lifts self into ReplyData::Rich if the current variant doesn’t
already carry headers (Json/Bytes/Empty/Stream), so middleware after
hooks (and any code that has a ReplyData it wants to decorate) can
stamp headers without manually wrangling ReplySpec. The original
payload is preserved.
To set a default — a header the handler may already have chosen —
check header first, or this overwrites its choice.
No-op on ReplyData::Upgrade — that variant is intercepted by the
server before the response body is finalized, and lifting it into
Rich would hide it from that interception.
Sourcepub fn set_status(&mut self, status: StatusCode)
pub fn set_status(&mut self, status: StatusCode)
Set the response status, lifting into ReplyData::Rich if needed
(see add_header).
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
The value this reply will send for header name, or None. The
name matches case-insensitively.
Follows the Finalizer: a header set on the reply
— by add_header, reply!’s headers = { … },
build_reply, or a constructor such as sse — wins; otherwise a
Json or Bytes payload’s own Content-Type is reported. Headers the
server adds later in the pipeline (compression’s Content-Encoding,
CORS, Vary, Date) are not visible here.
The fill-in-a-default idiom for an after middleware:
if response.header("cache-control").is_none() {
response.add_header("Cache-Control", "private, no-store");
}