1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::{
api::{Frame, Request},
imp::{core::*, prelude::*, response::Response as Impl, utils::Header}
};
#[derive(Debug)]
pub struct Response {
inner: Weak<Impl>
}
impl PartialEq for Response {
fn eq(&self, other: &Self) -> bool {
let a = self.inner.upgrade();
let b = other.inner.upgrade();
a.and_then(|a| b.map(|b| (a, b)))
.map(|(a, b)| a.guid() == b.guid())
.unwrap_or_default()
}
}
impl Response {
pub(crate) fn new(inner: Weak<Impl>) -> Self { Self { inner } }
pub fn url(&self) -> Result<String, Error> { Ok(upgrade(&self.inner)?.url().into()) }
pub fn status(&self) -> Result<i32, Error> { Ok(upgrade(&self.inner)?.status()) }
pub fn status_text(&self) -> Result<String, Error> {
Ok(upgrade(&self.inner)?.status_text().into())
}
pub fn ok(&self) -> Result<bool, Error> { Ok(upgrade(&self.inner)?.ok()) }
pub fn request(&self) -> Request {
let inner = weak_and_then(&self.inner, |rc| rc.request());
Request::new(inner)
}
pub async fn finished(&self) -> ArcResult<Option<String>> {
upgrade(&self.inner)?.finished().await
}
pub async fn body(&self) -> ArcResult<Vec<u8>> { upgrade(&self.inner)?.body().await }
pub async fn text(&self) -> ArcResult<String> { upgrade(&self.inner)?.text().await }
pub async fn headers(&self) -> ArcResult<Vec<Header>> { upgrade(&self.inner)?.headers().await }
pub fn frame(&self) -> Frame { self.request().frame() }
}