ttpkit_http/client/
response.rs

1//! Response types.
2
3use std::ops::Deref;
4
5use crate::{Body, Response, ResponseHeader, connection::Upgraded};
6
7/// Incoming HTTP response.
8pub struct IncomingResponse<B = Body> {
9    inner: Response<B>,
10    upgraded: Option<Upgraded>,
11}
12
13impl<B> IncomingResponse<B> {
14    /// Create a new incoming response.
15    pub const fn new(response: Response<B>) -> Self {
16        Self {
17            inner: response,
18            upgraded: None,
19        }
20    }
21
22    /// Take the response body.
23    #[inline]
24    pub fn body(self) -> B {
25        self.inner.body()
26    }
27
28    /// Deconstruct the response back into a response header and the body.
29    #[inline]
30    pub fn deconstruct(self) -> (ResponseHeader, B) {
31        self.inner.deconstruct()
32    }
33
34    /// Upgrade the connection (if possible).
35    #[inline]
36    pub fn upgrade(self) -> Option<Upgraded> {
37        self.upgraded
38    }
39
40    /// Attach upgraded connection.
41    pub(crate) fn with_upgraded_connection(mut self, upgraded: Upgraded) -> Self {
42        self.upgraded = Some(upgraded);
43        self
44    }
45}
46
47impl<B> Deref for IncomingResponse<B> {
48    type Target = Response<B>;
49
50    #[inline]
51    fn deref(&self) -> &Self::Target {
52        &self.inner
53    }
54}