#![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 RequestInitializer {
#[serde(rename = "frame", default, skip_serializing_if = "Option::is_none")]
pub frame: Option<Ref<Frame>>,
#[serde(rename = "serviceWorker", default, skip_serializing_if = "Option::is_none")]
pub service_worker: Option<Ref<Worker>>,
#[serde(rename = "url")]
pub url: String,
#[serde(rename = "resourceType")]
pub resource_type: String,
#[serde(rename = "method")]
pub method: String,
#[serde(rename = "postData", default, skip_serializing_if = "Option::is_none")]
pub post_data: Option<Binary>,
#[serde(rename = "headers")]
pub headers: Vec<NameValue>,
#[serde(rename = "isNavigationRequest")]
pub is_navigation_request: bool,
#[serde(rename = "redirectedFrom", default, skip_serializing_if = "Option::is_none")]
pub redirected_from: Option<Ref<Request>>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestResponseResult {
#[serde(rename = "response", default, skip_serializing_if = "Option::is_none")]
pub response: Option<Ref<Response>>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestRawRequestHeadersResult {
#[serde(rename = "headers")]
pub headers: Vec<NameValue>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum RequestEvent {
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for RequestEvent {
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 Request {
channel: Channel,
}
impl ChannelType for Request {
const INTERFACE: &'static str = "Request";
type Initializer = RequestInitializer;
type Event = RequestEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "Request")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl Request {
pub async fn response(&self) -> Result<RequestResponseResult, ProtocolError> {
self.channel.send("response", &serde_json::json!({})).await
}
pub async fn raw_request_headers(&self) -> Result<RequestRawRequestHeadersResult, ProtocolError> {
self.channel.send("rawRequestHeaders", &serde_json::json!({})).await
}
}