Skip to main content

Response

Struct Response 

Source
pub struct Response {
    pub status: u16,
    pub headers: HashMap<String, String>,
    pub raw_headers: Vec<Header>,
    /* private fields */
}
Expand description

A response. The body is a stream of byte-chunk results; a chunk is Err if the stream was reset or the connection failed mid-download, so a truncated body is never mistaken for a complete one (mirrors the TS body stream erroring).

Fields§

§status: u16§headers: HashMap<String, String>§raw_headers: Vec<Header>

Implementations§

Source§

impl Response

Source

pub fn into_body(self) -> ResponseBody

The response body as a backpressured stream of chunk results (Err on reset/failure). The receive window is replenished as chunks are pulled.

Source

pub async fn bytes(&mut self) -> Result<Vec<u8>, H2Error>

Buffer the whole body. Errors if the stream was reset or failed mid-download.

Source

pub async fn text(&mut self) -> Result<String, H2Error>

Buffer the body and decode it as UTF-8 (lossy).

Source

pub fn trailers(&self) -> Option<HashMap<String, String>>

Response trailers (a HEADERS block sent after the body), or None if there were none. Read the body to completion first — trailers arrive after it.

Source

pub fn into_parts(self) -> (ResponseBody, Trailers)

Split into the body stream and a trailer handle that outlives it.

into_body takes self while trailers needs &self, so a caller could otherwise stream the body or read the trailers, never both. gRPC needs both: its terminal status arrives in the trailers, after the last message — so on the streaming cardinalities a caller without this cannot tell a failed stream from a successfully empty one.

The TypeScript client has no such split (body and trailers() are both members of one object), so this is what keeps the two at parity.

Auto Trait Implementations§

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, 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.