Skip to main content

browser_commander/playwright/protocol/
request.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 `Request`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct RequestInitializer {
16    #[serde(rename = "frame", default, skip_serializing_if = "Option::is_none")]
17    pub frame: Option<Ref<Frame>>,
18    #[serde(rename = "serviceWorker", default, skip_serializing_if = "Option::is_none")]
19    pub service_worker: Option<Ref<Worker>>,
20    #[serde(rename = "url")]
21    pub url: String,
22    #[serde(rename = "resourceType")]
23    pub resource_type: String,
24    #[serde(rename = "method")]
25    pub method: String,
26    #[serde(rename = "postData", default, skip_serializing_if = "Option::is_none")]
27    pub post_data: Option<Binary>,
28    #[serde(rename = "headers")]
29    pub headers: Vec<NameValue>,
30    #[serde(rename = "isNavigationRequest")]
31    pub is_navigation_request: bool,
32    #[serde(rename = "redirectedFrom", default, skip_serializing_if = "Option::is_none")]
33    pub redirected_from: Option<Ref<Request>>,
34}
35
36/// Result of `Request.response`.
37#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
38pub struct RequestResponseResult {
39    #[serde(rename = "response", default, skip_serializing_if = "Option::is_none")]
40    pub response: Option<Ref<Response>>,
41}
42
43/// Result of `Request.rawRequestHeaders`.
44#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
45pub struct RequestRawRequestHeadersResult {
46    #[serde(rename = "headers")]
47    pub headers: Vec<NameValue>,
48}
49
50/// Events a `Request` channel can emit.
51#[derive(Debug, Clone, PartialEq)]
52pub enum RequestEvent {
53    /// An event this binding does not know (a newer driver).
54    Unknown {
55        /// Event name.
56        method: String,
57        /// Raw event parameters.
58        params: serde_json::Value,
59    },
60}
61
62impl ProtocolEvent for RequestEvent {
63    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
64        match method {
65            _ => Ok(Self::Unknown { method: method.to_string(), params }),
66        }
67    }
68}
69
70/// Channel for the `Request` interface (`network.yml`).
71#[derive(Debug, Clone)]
72pub struct Request {
73    channel: Channel,
74}
75
76impl ChannelType for Request {
77    const INTERFACE: &'static str = "Request";
78    type Initializer = RequestInitializer;
79    type Event = RequestEvent;
80
81    fn accepts(interface: &str) -> bool {
82        matches!(interface, "Request")
83    }
84
85    fn from_channel(channel: Channel) -> Self {
86        Self { channel }
87    }
88
89    fn channel(&self) -> &Channel {
90        &self.channel
91    }
92}
93
94impl Request {
95    /// `Request.response` (internal).
96    pub async fn response(&self) -> Result<RequestResponseResult, ProtocolError> {
97        self.channel.send("response", &serde_json::json!({})).await
98    }
99
100    /// `Request.rawRequestHeaders` (internal).
101    pub async fn raw_request_headers(&self) -> Result<RequestRawRequestHeadersResult, ProtocolError> {
102        self.channel.send("rawRequestHeaders", &serde_json::json!({})).await
103    }
104}