1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
14pub enum RequestStage {
15 Request,
17 Response,
19}
20
21impl RequestStage {
22 #[must_use]
24 pub fn as_cdp_str(&self) -> &'static str {
25 match self {
26 Self::Request => "Request",
27 Self::Response => "Response",
28 }
29 }
30}
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
39pub enum ResourceType {
40 Document,
41 Stylesheet,
42 Image,
43 Media,
44 Font,
45 Script,
46 TextTrack,
47 XHR,
48 Fetch,
49 EventSource,
50 WebSocket,
51 Manifest,
52 SignedExchange,
53 Ping,
54 CSPViolationReport,
55 Preflight,
56 Other,
57}
58
59impl ResourceType {
60 #[must_use]
63 pub fn as_cdp_str(&self) -> &'static str {
64 match self {
65 Self::Document => "Document",
66 Self::Stylesheet => "Stylesheet",
67 Self::Image => "Image",
68 Self::Media => "Media",
69 Self::Font => "Font",
70 Self::Script => "Script",
71 Self::TextTrack => "TextTrack",
72 Self::XHR => "XHR",
73 Self::Fetch => "Fetch",
74 Self::EventSource => "EventSource",
75 Self::WebSocket => "WebSocket",
76 Self::Manifest => "Manifest",
77 Self::SignedExchange => "SignedExchange",
78 Self::Ping => "Ping",
79 Self::CSPViolationReport => "CSPViolationReport",
80 Self::Preflight => "Preflight",
81 Self::Other => "Other",
82 }
83 }
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize)]
92pub enum AbortReason {
93 Failed,
94 Aborted,
95 TimedOut,
96 AccessDenied,
97 ConnectionClosed,
98 ConnectionReset,
99 ConnectionRefused,
100 ConnectionAborted,
101 ConnectionFailed,
102 NameNotResolved,
103 InternetDisconnected,
104 AddressUnreachable,
105 BlockedByClient,
106 BlockedByResponse,
107}
108
109impl AbortReason {
110 #[must_use]
113 pub fn as_cdp_str(&self) -> &'static str {
114 match self {
115 Self::Failed => "Failed",
116 Self::Aborted => "Aborted",
117 Self::TimedOut => "TimedOut",
118 Self::AccessDenied => "AccessDenied",
119 Self::ConnectionClosed => "ConnectionClosed",
120 Self::ConnectionReset => "ConnectionReset",
121 Self::ConnectionRefused => "ConnectionRefused",
122 Self::ConnectionAborted => "ConnectionAborted",
123 Self::ConnectionFailed => "ConnectionFailed",
124 Self::NameNotResolved => "NameNotResolved",
125 Self::InternetDisconnected => "InternetDisconnected",
126 Self::AddressUnreachable => "AddressUnreachable",
127 Self::BlockedByClient => "BlockedByClient",
128 Self::BlockedByResponse => "BlockedByResponse",
129 }
130 }
131}
132
133impl std::fmt::Display for AbortReason {
134 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
137 f.write_str(self.as_cdp_str())
138 }
139}
140
141#[derive(Debug, Clone)]
150pub struct RequestInfo {
151 pub url: String,
153 pub method: String,
155 pub headers: Vec<(String, String)>,
158 pub post_data: Option<Vec<u8>>,
161 pub resource_type: ResourceType,
163}
164
165#[derive(Debug, Clone)]
170pub struct ResponseInfo {
171 pub status: u16,
173 pub status_text: String,
175 pub headers: Vec<(String, String)>,
177}
178
179#[derive(Debug, Clone, Default)]
184pub struct RequestOverrides {
185 pub url: Option<String>,
187 pub method: Option<String>,
189 pub headers: Option<Vec<(String, String)>>,
193 pub post_data: Option<Vec<u8>>,
195}
196
197#[cfg(test)]
198#[allow(clippy::panic, clippy::unwrap_used)]
199mod tests {
200 use super::*;
201
202 #[test]
205 fn enum_cdp_strings_snapshot() {
206 let pairs = serde_json::json!({
207 "RequestStage": [
208 ["Request", RequestStage::Request.as_cdp_str()],
209 ["Response", RequestStage::Response.as_cdp_str()],
210 ],
211 "ResourceType": [
212 ["Document", ResourceType::Document.as_cdp_str()],
213 ["Stylesheet", ResourceType::Stylesheet.as_cdp_str()],
214 ["Image", ResourceType::Image.as_cdp_str()],
215 ["Media", ResourceType::Media.as_cdp_str()],
216 ["Font", ResourceType::Font.as_cdp_str()],
217 ["Script", ResourceType::Script.as_cdp_str()],
218 ["TextTrack", ResourceType::TextTrack.as_cdp_str()],
219 ["XHR", ResourceType::XHR.as_cdp_str()],
220 ["Fetch", ResourceType::Fetch.as_cdp_str()],
221 ["EventSource", ResourceType::EventSource.as_cdp_str()],
222 ["WebSocket", ResourceType::WebSocket.as_cdp_str()],
223 ["Manifest", ResourceType::Manifest.as_cdp_str()],
224 ["SignedExchange", ResourceType::SignedExchange.as_cdp_str()],
225 ["Ping", ResourceType::Ping.as_cdp_str()],
226 ["CSPViolationReport", ResourceType::CSPViolationReport.as_cdp_str()],
227 ["Preflight", ResourceType::Preflight.as_cdp_str()],
228 ["Other", ResourceType::Other.as_cdp_str()],
229 ],
230 "AbortReason": [
231 ["Failed", AbortReason::Failed.as_cdp_str()],
232 ["Aborted", AbortReason::Aborted.as_cdp_str()],
233 ["TimedOut", AbortReason::TimedOut.as_cdp_str()],
234 ["AccessDenied", AbortReason::AccessDenied.as_cdp_str()],
235 ["ConnectionClosed", AbortReason::ConnectionClosed.as_cdp_str()],
236 ["ConnectionReset", AbortReason::ConnectionReset.as_cdp_str()],
237 ["ConnectionRefused", AbortReason::ConnectionRefused.as_cdp_str()],
238 ["ConnectionAborted", AbortReason::ConnectionAborted.as_cdp_str()],
239 ["ConnectionFailed", AbortReason::ConnectionFailed.as_cdp_str()],
240 ["NameNotResolved", AbortReason::NameNotResolved.as_cdp_str()],
241 ["InternetDisconnected", AbortReason::InternetDisconnected.as_cdp_str()],
242 ["AddressUnreachable", AbortReason::AddressUnreachable.as_cdp_str()],
243 ["BlockedByClient", AbortReason::BlockedByClient.as_cdp_str()],
244 ["BlockedByResponse", AbortReason::BlockedByResponse.as_cdp_str()],
245 ],
246 });
247 insta::assert_yaml_snapshot!("enum_cdp_strings", pairs);
248 }
249
250 #[test]
251 fn abort_reason_display_matches_cdp_string() {
252 for reason in [
253 AbortReason::Failed,
254 AbortReason::BlockedByClient,
255 AbortReason::NameNotResolved,
256 ] {
257 assert_eq!(reason.to_string(), reason.as_cdp_str());
258 }
259 }
260}