browser-commander 0.18.0

Universal browser automation library that supports multiple browser engines with a unified API
Documentation
// @generated by scripts/generate-playwright-protocol.mjs from
// rust/protocol/playwright/*.yml. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports)]

use serde::{Deserialize, Serialize};

use super::*;
use crate::playwright::connection::{
    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};

/// Initializer the driver sends when it creates a `Response`.
#[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,
}

/// Result of `Response.body` (Get response body).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseBodyResult {
    #[serde(rename = "binary")]
    pub binary: Binary,
}

/// Result of `Response.securityDetails`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseSecurityDetailsResult {
    #[serde(rename = "value", default, skip_serializing_if = "Option::is_none")]
    pub value: Option<SecurityDetails>,
}

/// Result of `Response.serverAddr`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseServerAddrResult {
    #[serde(rename = "value", default, skip_serializing_if = "Option::is_none")]
    pub value: Option<RemoteAddr>,
}

/// Result of `Response.rawResponseHeaders`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseRawResponseHeadersResult {
    #[serde(rename = "headers")]
    pub headers: Vec<NameValue>,
}

/// Result of `Response.httpVersion`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseHttpVersionResult {
    #[serde(rename = "value")]
    pub value: String,
}

/// Result of `Response.sizes`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ResponseSizesResult {
    #[serde(rename = "sizes")]
    pub sizes: RequestSizes,
}

/// Events a `Response` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum ResponseEvent {
    /// An event this binding does not know (a newer driver).
    Unknown {
        /// Event name.
        method: String,
        /// Raw event parameters.
        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 }),
        }
    }
}

/// Channel for the `Response` interface (`network.yml`).
#[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 {
    /// `Response.body` ("Get response body").
    pub async fn body(&self) -> Result<ResponseBodyResult, ProtocolError> {
        self.channel.send("body", &serde_json::json!({})).await
    }

    /// `Response.securityDetails` (internal).
    pub async fn security_details(&self) -> Result<ResponseSecurityDetailsResult, ProtocolError> {
        self.channel.send("securityDetails", &serde_json::json!({})).await
    }

    /// `Response.serverAddr` (internal).
    pub async fn server_addr(&self) -> Result<ResponseServerAddrResult, ProtocolError> {
        self.channel.send("serverAddr", &serde_json::json!({})).await
    }

    /// `Response.rawResponseHeaders` (internal).
    pub async fn raw_response_headers(&self) -> Result<ResponseRawResponseHeadersResult, ProtocolError> {
        self.channel.send("rawResponseHeaders", &serde_json::json!({})).await
    }

    /// `Response.httpVersion` (internal).
    pub async fn http_version(&self) -> Result<ResponseHttpVersionResult, ProtocolError> {
        self.channel.send("httpVersion", &serde_json::json!({})).await
    }

    /// `Response.sizes` (internal).
    pub async fn sizes(&self) -> Result<ResponseSizesResult, ProtocolError> {
        self.channel.send("sizes", &serde_json::json!({})).await
    }
}