simple_request/
response.rs

1use hyper::{
2  StatusCode,
3  header::{HeaderValue, HeaderMap},
4  body::{Buf, Incoming},
5};
6use http_body_util::BodyExt;
7
8use crate::{Client, Error};
9
10// Borrows the client so its async task lives as long as this response exists.
11#[allow(dead_code)]
12#[derive(Debug)]
13pub struct Response<'a>(pub(crate) hyper::Response<Incoming>, pub(crate) &'a Client);
14impl<'a> Response<'a> {
15  pub fn status(&self) -> StatusCode {
16    self.0.status()
17  }
18  pub fn headers(&self) -> &HeaderMap<HeaderValue> {
19    self.0.headers()
20  }
21  pub async fn body(self) -> Result<impl std::io::Read, Error> {
22    Ok(self.0.into_body().collect().await.map_err(Error::Hyper)?.aggregate().reader())
23  }
24}