pub struct Response<P> {
pub status: u16,
pub metadata: HeaderList,
pub payload: P,
pub stream: Option<ResponseStream>,
pub upgrade: Option<UpgradeHandler>,
}Fields§
§status: u16§metadata: HeaderList§payload: PBuffered response payload. Bytes is the default wire case.
stream: Option<ResponseStream>Streamed response body. None for the buffered 80% case.
Response trailers (RFC 7230 §4.1.2) ride on the ResponseStream;
the listener emits them after the final 0-length chunk.
upgrade: Option<UpgradeHandler>When set, the listener hands the raw socket to this handler
after writing the response head. Body framing is suppressed
(no Transfer-Encoding, no body bytes) — the next bytes on
the wire belong to the handler’s protocol (CONNECT tunnel,
WebSocket frames, h2c SETTINGS, …).
Implementations§
Source§impl<P> Response<P>
impl<P> Response<P>
Sourcepub fn typed(status: u16, payload: P) -> Self
pub fn typed(status: u16, payload: P) -> Self
Construct a typed response with an explicit payload value.
Sourcepub fn with_stream(self, stream: ResponseStream) -> Self
pub fn with_stream(self, stream: ResponseStream) -> Self
Attach a streamed response body.
Sourcepub fn with_upgrade(self, handler: UpgradeHandler) -> Self
pub fn with_upgrade(self, handler: UpgradeHandler) -> Self
Attach an upgrade handler. The listener writes this response’s head, then hands the raw socket to the handler. Typically paired with status 200 (CONNECT) or 101 (Upgrade).
pub fn with_header( self, name: impl IntoHeaderBytes, value: impl IntoHeaderBytes, ) -> Self
pub fn is_success(&self) -> bool
pub fn is_no_data(&self) -> bool
Source§impl Response<Bytes>
impl Response<Bytes>
pub fn new(status: u16) -> Self
pub fn with_payload(self, payload: impl Into<Bytes>) -> Self
pub fn with_body(self, body: impl Into<Bytes>) -> Self
Sourcepub fn streamed(stream: ResponseStream) -> Self
pub fn streamed(stream: ResponseStream) -> Self
Construct a streamed response (status 200).
pub fn ok(payload: impl Into<Bytes>) -> Self
pub fn not_found() -> Self
pub fn no_data() -> Self
Sourcepub fn into_chunk_stream(self) -> ChunkStream
pub fn into_chunk_stream(self) -> ChunkStream
Uniform chunk-stream view of the response payload: the streamed body if present, else a one-chunk stream of the buffered bytes. Lets a listener pump any response without matching on the shape.
Sourcepub async fn collect_body(self) -> Result<Bytes, ProximaError>
pub async fn collect_body(self) -> Result<Bytes, ProximaError>
Drain the response payload to Bytes — the streamed body collected,
else the buffered bytes. Not cancellation-aware; for that,
take self.stream and call ResponseStream::collect(Some(&token)).
Trait Implementations§
Source§impl ApplyOps<ResponseOp> for Response<Bytes>
Available on crate feature std only.
impl ApplyOps<ResponseOp> for Response<Bytes>
std only.fn apply(self, ops: &[ResponseOp]) -> Self
Source§impl BytePayload for Response<Bytes>
impl BytePayload for Response<Bytes>
Source§impl Idempotent for Response<Bytes>
impl Idempotent for Response<Bytes>
fn is_idempotent(&self) -> bool
Source§impl Replayable for Response<Bytes>
Available on crate feature std only.
impl Replayable for Response<Bytes>
std only.