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