Skip to main content

Response

Struct Response 

Source
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: P

Buffered 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>

Source

pub fn typed(status: u16, payload: P) -> Self

Construct a typed response with an explicit payload value.

Source

pub fn with_stream(self, stream: ResponseStream) -> Self

Attach a streamed response body.

Source

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).

Source

pub fn with_header( self, name: impl IntoHeaderBytes, value: impl IntoHeaderBytes, ) -> Self

Source

pub fn is_success(&self) -> bool

Source

pub fn is_no_data(&self) -> bool

Source§

impl Response<Bytes>

Source

pub fn new(status: u16) -> Self

Source

pub fn with_payload(self, payload: impl Into<Bytes>) -> Self

Source

pub fn with_body(self, body: impl Into<Bytes>) -> Self

Source

pub fn streamed(stream: ResponseStream) -> Self

Construct a streamed response (status 200).

Source

pub fn ok(payload: impl Into<Bytes>) -> Self

Source

pub fn not_found() -> Self

Source

pub fn no_data() -> Self

Source

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.

Source

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

fn apply(self, ops: &[ResponseOp]) -> Self

Source§

impl BytePayload for Response<Bytes>

Source§

fn set_bytes(&mut self, bytes: Bytes)

Replace the payload’s bytes with bytes.
Source§

fn bytes(&self) -> &[u8] ⓘ

Borrow the payload’s current bytes.
Source§

impl<P: Debug> Debug for Response<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Idempotent for Response<Bytes>

Source§

impl Labeled for Response<Bytes>

Source§

impl Replayable for Response<Bytes>

Available on crate feature std only.
Source§

impl Retryable for Response<Bytes>

Auto Trait Implementations§

§

impl<P> !RefUnwindSafe for Response<P>

§

impl<P> !Sync for Response<P>

§

impl<P> !UnwindSafe for Response<P>

§

impl<P> Freeze for Response<P>
where P: Freeze,

§

impl<P> Send for Response<P>
where P: Send,

§

impl<P> Unpin for Response<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for Response<P>
where P: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more