viewpoint_cdp/protocol/
network.rs

1//! Network domain types.
2//!
3//! The Network domain allows tracking network activities of the page.
4
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8/// Unique request identifier.
9pub type RequestId = String;
10
11/// Unique loader identifier.
12pub type LoaderId = String;
13
14/// Unique frame identifier.
15pub type FrameId = String;
16
17/// HTTP request data.
18#[derive(Debug, Clone, Deserialize)]
19#[serde(rename_all = "camelCase")]
20pub struct Request {
21    /// Request URL.
22    pub url: String,
23    /// HTTP request method.
24    pub method: String,
25    /// HTTP request headers.
26    pub headers: HashMap<String, String>,
27    /// HTTP POST request data.
28    pub post_data: Option<String>,
29    /// Whether the request has POST data.
30    pub has_post_data: Option<bool>,
31    /// Request body mixed content type.
32    pub mixed_content_type: Option<String>,
33    /// The referrer policy of the request.
34    pub referrer_policy: Option<String>,
35    /// Whether is loaded via link preload.
36    pub is_link_preload: Option<bool>,
37}
38
39/// HTTP response data.
40#[derive(Debug, Clone, Deserialize)]
41#[serde(rename_all = "camelCase")]
42pub struct Response {
43    /// Response URL.
44    pub url: String,
45    /// HTTP response status code.
46    pub status: u32,
47    /// HTTP response status text.
48    pub status_text: String,
49    /// HTTP response headers.
50    pub headers: HashMap<String, String>,
51    /// HTTP response headers text.
52    pub headers_text: Option<String>,
53    /// Resource mimeType.
54    pub mime_type: String,
55    /// Refined HTTP request headers that were actually transmitted over the network.
56    pub request_headers: Option<HashMap<String, String>>,
57    /// HTTP request headers text.
58    pub request_headers_text: Option<String>,
59    /// Whether the response was served from disk cache.
60    pub from_disk_cache: Option<bool>,
61    /// Whether the response was served from the prefetch cache.
62    pub from_prefetch_cache: Option<bool>,
63    /// Whether the response was served from `ServiceWorker`.
64    pub from_service_worker: Option<bool>,
65    /// Total number of bytes received.
66    pub encoded_data_length: Option<f64>,
67    /// Protocol for the request.
68    pub protocol: Option<String>,
69    /// Security state.
70    pub security_state: Option<String>,
71}
72
73/// Parameters for Network.enable.
74#[derive(Debug, Clone, Serialize, Default)]
75#[serde(rename_all = "camelCase")]
76pub struct EnableParams {
77    /// Buffer size in bytes to use for storing network data.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub max_total_buffer_size: Option<i64>,
80    /// Per-resource buffer size in bytes.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub max_resource_buffer_size: Option<i64>,
83    /// Max post data size in bytes.
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub max_post_data_size: Option<i64>,
86}
87
88/// Event: Network.requestWillBeSent
89#[derive(Debug, Clone, Deserialize)]
90#[serde(rename_all = "camelCase")]
91pub struct RequestWillBeSentEvent {
92    /// Request identifier.
93    pub request_id: RequestId,
94    /// Loader identifier.
95    pub loader_id: LoaderId,
96    /// URL of the document this request is loaded for.
97    pub document_url: String,
98    /// Request data.
99    pub request: Request,
100    /// Timestamp.
101    pub timestamp: f64,
102    /// Timestamp.
103    pub wall_time: f64,
104    /// Request initiator.
105    pub initiator: RequestInitiator,
106    /// Frame identifier.
107    pub frame_id: Option<FrameId>,
108    /// Whether this request is a navigation request.
109    pub has_user_gesture: Option<bool>,
110    /// Type of the request.
111    #[serde(rename = "type")]
112    pub resource_type: Option<String>,
113}
114
115/// Request initiator information.
116#[derive(Debug, Clone, Deserialize)]
117#[serde(rename_all = "camelCase")]
118pub struct RequestInitiator {
119    /// Type of initiator.
120    #[serde(rename = "type")]
121    pub initiator_type: String,
122    /// Initiator URL.
123    pub url: Option<String>,
124    /// Initiator line number.
125    pub line_number: Option<f64>,
126    /// Initiator column number.
127    pub column_number: Option<f64>,
128}
129
130/// Event: Network.responseReceived
131#[derive(Debug, Clone, Deserialize)]
132#[serde(rename_all = "camelCase")]
133pub struct ResponseReceivedEvent {
134    /// Request identifier.
135    pub request_id: RequestId,
136    /// Loader identifier.
137    pub loader_id: LoaderId,
138    /// Timestamp.
139    pub timestamp: f64,
140    /// Resource type.
141    #[serde(rename = "type")]
142    pub resource_type: String,
143    /// Response data.
144    pub response: Response,
145    /// Frame identifier.
146    pub frame_id: Option<FrameId>,
147}
148
149/// Event: Network.loadingFinished
150#[derive(Debug, Clone, Deserialize)]
151#[serde(rename_all = "camelCase")]
152pub struct LoadingFinishedEvent {
153    /// Request identifier.
154    pub request_id: RequestId,
155    /// Timestamp.
156    pub timestamp: f64,
157    /// Total number of bytes received.
158    pub encoded_data_length: f64,
159}
160
161/// Event: Network.loadingFailed
162#[derive(Debug, Clone, Deserialize)]
163#[serde(rename_all = "camelCase")]
164pub struct LoadingFailedEvent {
165    /// Request identifier.
166    pub request_id: RequestId,
167    /// Timestamp.
168    pub timestamp: f64,
169    /// Resource type.
170    #[serde(rename = "type")]
171    pub resource_type: String,
172    /// User friendly error message.
173    pub error_text: String,
174    /// True if loading was canceled.
175    pub canceled: Option<bool>,
176    /// The reason why loading was blocked.
177    pub blocked_reason: Option<String>,
178}
179
180/// Event: Network.requestServedFromCache
181#[derive(Debug, Clone, Deserialize)]
182#[serde(rename_all = "camelCase")]
183pub struct RequestServedFromCacheEvent {
184    /// Request identifier.
185    pub request_id: RequestId,
186}