Skip to main content

Module respond

Module respond 

Source
Expand description

Turning a run’s event stream into an HTTP response.

Two things happen here that are easy to get wrong.

Negotiation is a decision, not a fallback. negotiate asks crate::encode::media_type what to answer with and refuses the request when the answer is “nothing” — a client that asked for application/xml gets a 406, not an SSE stream it cannot read.

The body owns the run. Polling the stream is running the agent (crate::server::run() has no executor of its own), so the response body and the run have exactly the same lifetime. That is what makes disconnect handling work: when the client goes away hyper drops the body, and the body drops a guard that trips the run’s CancellationToken. See SseResponse::cancellation.

Structs§

SseResponse
A negotiated event-stream response, waiting for the stream to put in it.

Functions§

negotiate
Picks the response encoding for an Accept header.