playwright_core/protocol/
response.rs

1// Response protocol object
2//
3// Represents an HTTP response from navigation operations.
4// Response objects are created by the server when Frame.goto() or similar navigation
5// methods complete successfully.
6
7use crate::channel_owner::{ChannelOwner, ChannelOwnerImpl, ParentOrConnection};
8use crate::error::Result;
9use serde_json::Value;
10use std::any::Any;
11use std::sync::Arc;
12
13/// Response represents an HTTP response from a navigation operation.
14///
15/// Response objects are not created directly - they are returned from
16/// navigation methods like page.goto() or page.reload().
17///
18/// See: <https://playwright.dev/docs/api/class-response>
19#[derive(Clone)]
20pub struct ResponseObject {
21    base: ChannelOwnerImpl,
22}
23
24impl ResponseObject {
25    /// Creates a new Response from protocol initialization
26    ///
27    /// This is called by the object factory when the server sends a `__create__` message
28    /// for a Response object.
29    pub fn new(
30        parent: Arc<dyn ChannelOwner>,
31        type_name: String,
32        guid: Arc<str>,
33        initializer: Value,
34    ) -> Result<Self> {
35        let base = ChannelOwnerImpl::new(
36            ParentOrConnection::Parent(parent),
37            type_name,
38            guid,
39            initializer,
40        );
41
42        Ok(Self { base })
43    }
44}
45
46impl ChannelOwner for ResponseObject {
47    fn guid(&self) -> &str {
48        self.base.guid()
49    }
50
51    fn type_name(&self) -> &str {
52        self.base.type_name()
53    }
54
55    fn parent(&self) -> Option<Arc<dyn ChannelOwner>> {
56        self.base.parent()
57    }
58
59    fn connection(&self) -> Arc<dyn crate::connection::ConnectionLike> {
60        self.base.connection()
61    }
62
63    fn initializer(&self) -> &Value {
64        self.base.initializer()
65    }
66
67    fn channel(&self) -> &crate::channel::Channel {
68        self.base.channel()
69    }
70
71    fn dispose(&self, reason: crate::channel_owner::DisposeReason) {
72        self.base.dispose(reason)
73    }
74
75    fn adopt(&self, child: Arc<dyn ChannelOwner>) {
76        self.base.adopt(child)
77    }
78
79    fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>) {
80        self.base.add_child(guid, child)
81    }
82
83    fn remove_child(&self, guid: &str) {
84        self.base.remove_child(guid)
85    }
86
87    fn on_event(&self, _method: &str, _params: Value) {
88        // Response objects don't have events
89    }
90
91    fn was_collected(&self) -> bool {
92        self.base.was_collected()
93    }
94
95    fn as_any(&self) -> &dyn Any {
96        self
97    }
98}
99
100impl std::fmt::Debug for ResponseObject {
101    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
102        f.debug_struct("ResponseObject")
103            .field("guid", &self.guid())
104            .finish()
105    }
106}