use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct Request {
pub url: String,
pub method: String,
pub headers: HashMap<String, String>,
pub allow_revisit: bool,
pub context: HashMap<String, String>,
pub body: Vec<u8>,
pub aborted: bool,
}
impl Request {
pub fn get(url: &str) -> Self {
Self {
url: url.to_string(),
method: "GET".into(),
headers: HashMap::new(),
allow_revisit: false,
context: HashMap::new(),
body: Vec::new(),
aborted: false,
}
}
pub fn post(url: &str, body: Vec<u8>) -> Self {
Self {
url: url.to_string(),
method: "POST".into(),
headers: HashMap::new(),
allow_revisit: false,
context: HashMap::new(),
body,
aborted: false,
}
}
pub fn header(mut self, key: &str, value: &str) -> Self {
self.headers.insert(key.to_string(), value.to_string());
self
}
pub fn set_context(mut self, key: &str, value: &str) -> Self {
self.context.insert(key.to_string(), value.to_string());
self
}
pub fn abort(&mut self) {
self.aborted = true;
}
}