#![allow(clippy::all, missing_docs, unused_imports)]
use serde::{Deserialize, Serialize};
use super::*;
use crate::playwright::connection::{
Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseInitializer {
#[serde(rename = "request")]
pub request: Ref<Request>,
#[serde(rename = "url")]
pub url: String,
#[serde(rename = "status")]
pub status: i64,
#[serde(rename = "statusText")]
pub status_text: String,
#[serde(rename = "headers")]
pub headers: Vec<NameValue>,
#[serde(rename = "timing")]
pub timing: ResourceTiming,
#[serde(rename = "fromServiceWorker")]
pub from_service_worker: bool,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseBodyResult {
#[serde(rename = "binary")]
pub binary: Binary,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseSecurityDetailsResult {
#[serde(rename = "value", default, skip_serializing_if = "Option::is_none")]
pub value: Option<SecurityDetails>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseServerAddrResult {
#[serde(rename = "value", default, skip_serializing_if = "Option::is_none")]
pub value: Option<RemoteAddr>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseRawResponseHeadersResult {
#[serde(rename = "headers")]
pub headers: Vec<NameValue>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseHttpVersionResult {
#[serde(rename = "value")]
pub value: String,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseSizesResult {
#[serde(rename = "sizes")]
pub sizes: RequestSizes,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ResponseEvent {
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for ResponseEvent {
fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
match method {
_ => Ok(Self::Unknown { method: method.to_string(), params }),
}
}
}
#[derive(Debug, Clone)]
pub struct Response {
channel: Channel,
}
impl ChannelType for Response {
const INTERFACE: &'static str = "Response";
type Initializer = ResponseInitializer;
type Event = ResponseEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "Response")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl Response {
pub async fn body(&self) -> Result<ResponseBodyResult, ProtocolError> {
self.channel.send("body", &serde_json::json!({})).await
}
pub async fn security_details(&self) -> Result<ResponseSecurityDetailsResult, ProtocolError> {
self.channel.send("securityDetails", &serde_json::json!({})).await
}
pub async fn server_addr(&self) -> Result<ResponseServerAddrResult, ProtocolError> {
self.channel.send("serverAddr", &serde_json::json!({})).await
}
pub async fn raw_response_headers(&self) -> Result<ResponseRawResponseHeadersResult, ProtocolError> {
self.channel.send("rawResponseHeaders", &serde_json::json!({})).await
}
pub async fn http_version(&self) -> Result<ResponseHttpVersionResult, ProtocolError> {
self.channel.send("httpVersion", &serde_json::json!({})).await
}
pub async fn sizes(&self) -> Result<ResponseSizesResult, ProtocolError> {
self.channel.send("sizes", &serde_json::json!({})).await
}
}