chromiumoxide/handler/
http.rs

1use chromiumoxide_cdp::cdp::browser_protocol::network::{InterceptionId, RequestId, Response};
2use chromiumoxide_cdp::cdp::browser_protocol::page::FrameId;
3
4#[derive(Default, Debug, Clone)]
5pub struct HttpRequest {
6    /// Unique ID of the request.
7    request_id: RequestId,
8    /// Indicates if the response came from the memory cache.
9    pub from_memory_cache: bool,
10    /// Reason for failure, if any.
11    pub failure_text: Option<String>,
12    /// ID used for request interception, if applicable.
13    pub interception_id: Option<InterceptionId>,
14    /// Response data associated with the request.
15    pub response: Option<Response>,
16    /// HTTP headers of the request.
17    pub headers: std::collections::HashMap<String, String>,
18    /// ID of the frame that initiated the request.
19    pub frame: Option<FrameId>,
20    /// Whether this is a navigation request.
21    pub is_navigation_request: bool,
22    /// Whether interception is allowed for this request.
23    pub allow_interception: bool,
24    /// Whether the interception has already been handled.
25    pub interception_handled: bool,
26    /// HTTP method (e.g., GET, POST).
27    pub method: Option<String>,
28    /// Request URL.
29    pub url: Option<String>,
30    /// Resource type (e.g., "Document", "Script").
31    pub resource_type: Option<String>,
32    /// Raw post body, if present.
33    pub post_data: Option<String>,
34    /// List of redirect requests leading to this one.
35    pub redirect_chain: Vec<HttpRequest>,
36}
37
38impl HttpRequest {
39    /// Creates a new `HttpRequest` with the given request ID and default values.
40    pub fn new(
41        request_id: RequestId,
42        frame: Option<FrameId>,
43        interception_id: Option<InterceptionId>,
44        allow_interception: bool,
45        redirect_chain: Vec<HttpRequest>,
46    ) -> Self {
47        Self {
48            request_id,
49            from_memory_cache: false,
50            failure_text: None,
51            interception_id,
52            response: None,
53            headers: Default::default(),
54            frame,
55            is_navigation_request: false,
56            allow_interception,
57            interception_handled: false,
58            method: None,
59            url: None,
60            resource_type: None,
61            post_data: None,
62            redirect_chain,
63        }
64    }
65    /// Returns the request ID.
66    pub fn request_id(&self) -> &RequestId {
67        &self.request_id
68    }
69    /// Sets the response for this request.
70    pub fn set_response(&mut self, response: Response) {
71        self.response = Some(response)
72    }
73}