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
impl Response
Sourcepub fn into_body(self) -> ResponseBody
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.
Sourcepub async fn bytes(&mut self) -> Result<Vec<u8>, H2Error>
pub async fn bytes(&mut self) -> Result<Vec<u8>, H2Error>
Buffer the whole body. Errors if the stream was reset or failed mid-download.
Sourcepub async fn text(&mut self) -> Result<String, H2Error>
pub async fn text(&mut self) -> Result<String, H2Error>
Buffer the body and decode it as UTF-8 (lossy).
Sourcepub fn trailers(&self) -> Option<HashMap<String, String>>
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.
Sourcepub fn into_parts(self) -> (ResponseBody, Trailers)
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.