1use std::collections::HashMap;
4
5#[derive(Debug, Clone)]
9pub struct Request {
10 pub url: String,
12 pub method: String,
14 pub headers: HashMap<String, String>,
16 pub allow_revisit: bool,
18 pub context: HashMap<String, String>,
20 pub body: Vec<u8>,
22 pub aborted: bool,
24}
25
26impl Request {
27 pub fn get(url: &str) -> Self {
29 Self {
30 url: url.to_string(),
31 method: "GET".into(),
32 headers: HashMap::new(),
33 allow_revisit: false,
34 context: HashMap::new(),
35 body: Vec::new(),
36 aborted: false,
37 }
38 }
39
40 pub fn post(url: &str, body: Vec<u8>) -> Self {
42 Self {
43 url: url.to_string(),
44 method: "POST".into(),
45 headers: HashMap::new(),
46 allow_revisit: false,
47 context: HashMap::new(),
48 body,
49 aborted: false,
50 }
51 }
52
53 pub fn header(mut self, key: &str, value: &str) -> Self {
55 self.headers.insert(key.to_string(), value.to_string());
56 self
57 }
58
59 pub fn set_context(mut self, key: &str, value: &str) -> Self {
61 self.context.insert(key.to_string(), value.to_string());
62 self
63 }
64
65 pub fn abort(&mut self) {
69 self.aborted = true;
70 }
71}