pub struct ResponseContext {
pub status: u16,
pub headers: HeaderMap,
pub body: Vec<u8>,
pub was_sse: bool,
pub json: Option<Value>,
pub json_mutated: bool,
pub rpc_error: Option<(i64, String)>,
pub upstream_us: Option<u64>,
}Expand description
Response-side state threaded through the response middleware chain.
Middleware mutate body and json in place. Handlers instantiate after
reading the upstream body and finalize by building an axum::Response from
(status, headers, body).
Fields§
§status: u16§headers: HeaderMap§body: Vec<u8>Serialized response body — what gets returned to the client. Held
verbatim from the upstream until EncodeResponseJson overwrites it.
When no middleware mutates json, this retains the original bytes
byte-for-byte (preserving SSE framing, key order, etc.).
was_sse: boolTrue when the upstream sent SSE-wrapped JSON. DecodeResponseJson
sets it; EncodeResponseJson reads it to decide whether to re-wrap.
json: Option<Value>Parsed JSON view of the body. Populated by DecodeResponseJson;
mutated by later middleware; serialized back into body by
EncodeResponseJson only when json_mutated is set.
json_mutated: boolSignals that some middleware mutated json. Set by any middleware
that takes json.as_mut() or reassigns json. EncodeResponseJson
skips re-serialization when false, leaving body untouched — the
byte-pass fast path.
rpc_error: Option<(i64, String)>JSON-RPC error extracted from json (when present).
upstream_us: Option<u64>