browser_commander/playwright/protocol/
response.rs1#![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#[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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
34pub struct ResponseBodyResult {
35 #[serde(rename = "binary")]
36 pub binary: Binary,
37}
38
39#[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#[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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
55pub struct ResponseRawResponseHeadersResult {
56 #[serde(rename = "headers")]
57 pub headers: Vec<NameValue>,
58}
59
60#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
62pub struct ResponseHttpVersionResult {
63 #[serde(rename = "value")]
64 pub value: String,
65}
66
67#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
69pub struct ResponseSizesResult {
70 #[serde(rename = "sizes")]
71 pub sizes: RequestSizes,
72}
73
74#[derive(Debug, Clone, PartialEq)]
76pub enum ResponseEvent {
77 Unknown {
79 method: String,
81 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#[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 pub async fn body(&self) -> Result<ResponseBodyResult, ProtocolError> {
121 self.channel.send("body", &serde_json::json!({})).await
122 }
123
124 pub async fn security_details(&self) -> Result<ResponseSecurityDetailsResult, ProtocolError> {
126 self.channel.send("securityDetails", &serde_json::json!({})).await
127 }
128
129 pub async fn server_addr(&self) -> Result<ResponseServerAddrResult, ProtocolError> {
131 self.channel.send("serverAddr", &serde_json::json!({})).await
132 }
133
134 pub async fn raw_response_headers(&self) -> Result<ResponseRawResponseHeadersResult, ProtocolError> {
136 self.channel.send("rawResponseHeaders", &serde_json::json!({})).await
137 }
138
139 pub async fn http_version(&self) -> Result<ResponseHttpVersionResult, ProtocolError> {
141 self.channel.send("httpVersion", &serde_json::json!({})).await
142 }
143
144 pub async fn sizes(&self) -> Result<ResponseSizesResult, ProtocolError> {
146 self.channel.send("sizes", &serde_json::json!({})).await
147 }
148}