Skip to main content

browser_commander/playwright/protocol/
response.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Initializer the driver sends when it creates a `Response`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct ResponseInitializer {
16    #[serde(rename = "request")]
17    pub request: Ref<Request>,
18    #[serde(rename = "url")]
19    pub url: String,
20    #[serde(rename = "status")]
21    pub status: i64,
22    #[serde(rename = "statusText")]
23    pub status_text: String,
24    #[serde(rename = "headers")]
25    pub headers: Vec<NameValue>,
26    #[serde(rename = "timing")]
27    pub timing: ResourceTiming,
28    #[serde(rename = "fromServiceWorker")]
29    pub from_service_worker: bool,
30}
31
32/// Result of `Response.body` (Get response body).
33#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
34pub struct ResponseBodyResult {
35    #[serde(rename = "binary")]
36    pub binary: Binary,
37}
38
39/// Result of `Response.securityDetails`.
40#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
41pub struct ResponseSecurityDetailsResult {
42    #[serde(rename = "value", default, skip_serializing_if = "Option::is_none")]
43    pub value: Option<SecurityDetails>,
44}
45
46/// Result of `Response.serverAddr`.
47#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
48pub struct ResponseServerAddrResult {
49    #[serde(rename = "value", default, skip_serializing_if = "Option::is_none")]
50    pub value: Option<RemoteAddr>,
51}
52
53/// Result of `Response.rawResponseHeaders`.
54#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
55pub struct ResponseRawResponseHeadersResult {
56    #[serde(rename = "headers")]
57    pub headers: Vec<NameValue>,
58}
59
60/// Result of `Response.httpVersion`.
61#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
62pub struct ResponseHttpVersionResult {
63    #[serde(rename = "value")]
64    pub value: String,
65}
66
67/// Result of `Response.sizes`.
68#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
69pub struct ResponseSizesResult {
70    #[serde(rename = "sizes")]
71    pub sizes: RequestSizes,
72}
73
74/// Events a `Response` channel can emit.
75#[derive(Debug, Clone, PartialEq)]
76pub enum ResponseEvent {
77    /// An event this binding does not know (a newer driver).
78    Unknown {
79        /// Event name.
80        method: String,
81        /// Raw event parameters.
82        params: serde_json::Value,
83    },
84}
85
86impl ProtocolEvent for ResponseEvent {
87    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
88        match method {
89            _ => Ok(Self::Unknown { method: method.to_string(), params }),
90        }
91    }
92}
93
94/// Channel for the `Response` interface (`network.yml`).
95#[derive(Debug, Clone)]
96pub struct Response {
97    channel: Channel,
98}
99
100impl ChannelType for Response {
101    const INTERFACE: &'static str = "Response";
102    type Initializer = ResponseInitializer;
103    type Event = ResponseEvent;
104
105    fn accepts(interface: &str) -> bool {
106        matches!(interface, "Response")
107    }
108
109    fn from_channel(channel: Channel) -> Self {
110        Self { channel }
111    }
112
113    fn channel(&self) -> &Channel {
114        &self.channel
115    }
116}
117
118impl Response {
119    /// `Response.body` ("Get response body").
120    pub async fn body(&self) -> Result<ResponseBodyResult, ProtocolError> {
121        self.channel.send("body", &serde_json::json!({})).await
122    }
123
124    /// `Response.securityDetails` (internal).
125    pub async fn security_details(&self) -> Result<ResponseSecurityDetailsResult, ProtocolError> {
126        self.channel.send("securityDetails", &serde_json::json!({})).await
127    }
128
129    /// `Response.serverAddr` (internal).
130    pub async fn server_addr(&self) -> Result<ResponseServerAddrResult, ProtocolError> {
131        self.channel.send("serverAddr", &serde_json::json!({})).await
132    }
133
134    /// `Response.rawResponseHeaders` (internal).
135    pub async fn raw_response_headers(&self) -> Result<ResponseRawResponseHeadersResult, ProtocolError> {
136        self.channel.send("rawResponseHeaders", &serde_json::json!({})).await
137    }
138
139    /// `Response.httpVersion` (internal).
140    pub async fn http_version(&self) -> Result<ResponseHttpVersionResult, ProtocolError> {
141        self.channel.send("httpVersion", &serde_json::json!({})).await
142    }
143
144    /// `Response.sizes` (internal).
145    pub async fn sizes(&self) -> Result<ResponseSizesResult, ProtocolError> {
146        self.channel.send("sizes", &serde_json::json!({})).await
147    }
148}