chromiumoxide/handler/
http.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use chromiumoxide_cdp::cdp::browser_protocol::network::{InterceptionId, RequestId, Response};
use chromiumoxide_cdp::cdp::browser_protocol::page::FrameId;

#[derive(Debug, Clone)]
pub struct HttpRequest {
    request_id: RequestId,
    pub from_memory_cache: bool,
    pub failure_text: Option<String>,
    pub interception_id: Option<InterceptionId>,
    pub response: Option<Response>,
    pub headers: std::collections::HashMap<String, String>,
    pub frame: Option<FrameId>,
    pub is_navigation_request: bool,
    pub allow_interception: bool,
    pub interception_handled: bool,
    pub method: Option<String>,
    pub url: Option<String>,
    pub resource_type: Option<String>,
    pub post_data: Option<String>,
    pub redirect_chain: Vec<HttpRequest>,
}

impl HttpRequest {
    pub fn new(
        request_id: RequestId,
        frame: Option<FrameId>,
        interception_id: Option<InterceptionId>,
        allow_interception: bool,
        redirect_chain: Vec<HttpRequest>,
    ) -> Self {
        Self {
            request_id,
            from_memory_cache: false,
            failure_text: None,
            interception_id,
            response: None,
            headers: Default::default(),
            frame,
            is_navigation_request: false,
            allow_interception,
            interception_handled: false,
            method: None,
            url: None,
            resource_type: None,
            post_data: None,
            redirect_chain,
        }
    }

    pub fn request_id(&self) -> &RequestId {
        &self.request_id
    }

    pub(crate) fn set_response(&mut self, response: Response) {
        self.response = Some(response)
    }
}