chromiumoxide/handler/
http.rs1use std::time::Instant;
2
3use chromiumoxide_cdp::cdp::browser_protocol::network::{InterceptionId, RequestId, Response};
4use chromiumoxide_cdp::cdp::browser_protocol::page::FrameId;
5
6#[derive(Debug, Clone)]
7pub struct HttpRequest {
8 pub request_id: RequestId,
10 pub from_memory_cache: bool,
12 pub failure_text: Option<String>,
14 pub interception_id: Option<InterceptionId>,
16 pub response: Option<Response>,
18 pub headers: std::collections::HashMap<String, String>,
20 pub frame: Option<FrameId>,
22 pub is_navigation_request: bool,
24 pub allow_interception: bool,
26 pub interception_handled: bool,
28 pub method: Option<String>,
30 pub url: Option<String>,
32 pub resource_type: Option<String>,
34 pub post_data: Option<String>,
36 pub redirect_chain: Vec<HttpRequest>,
38 pub created_at: Instant,
41}
42
43impl Default for HttpRequest {
44 fn default() -> Self {
45 Self {
46 request_id: Default::default(),
47 from_memory_cache: false,
48 failure_text: None,
49 interception_id: None,
50 response: None,
51 headers: Default::default(),
52 frame: None,
53 is_navigation_request: false,
54 allow_interception: false,
55 interception_handled: false,
56 method: None,
57 url: None,
58 resource_type: None,
59 post_data: None,
60 redirect_chain: Vec::new(),
61 created_at: Instant::now(),
62 }
63 }
64}
65
66impl HttpRequest {
67 pub fn new(
69 request_id: RequestId,
70 frame: Option<FrameId>,
71 interception_id: Option<InterceptionId>,
72 allow_interception: bool,
73 redirect_chain: Vec<HttpRequest>,
74 ) -> Self {
75 Self {
76 request_id,
77 from_memory_cache: false,
78 failure_text: None,
79 interception_id,
80 response: None,
81 headers: Default::default(),
82 frame,
83 is_navigation_request: false,
84 allow_interception,
85 interception_handled: false,
86 method: None,
87 url: None,
88 resource_type: None,
89 post_data: None,
90 redirect_chain,
91 created_at: Instant::now(),
92 }
93 }
94 pub fn request_id(&self) -> &RequestId {
96 &self.request_id
97 }
98 pub fn set_response(&mut self, response: Response) {
100 self.response = Some(response)
101 }
102}