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
58
59
use std::{collections::HashMap, time::Duration};
use reqwest::{header::HeaderMap, Method, StatusCode};
#[derive(Debug)]
pub struct Request {
pub url: String,
pub expected: StatusCode,
pub method: reqwest::Method,
pub expect_body: bool,
pub headers: HeaderMap,
pub search_params: HashMap<String, Vec<String>>,
}
impl Request {
pub fn default() -> Self {
Self {
expect_body: true,
expected: StatusCode::OK,
headers: HeaderMap::default(),
method: Method::GET,
url: "".to_string(),
search_params: HashMap::new(),
}
}
}
#[derive(Debug)]
pub struct Response {
pub body: Option<String>,
pub status: StatusCode,
pub headers: HeaderMap,
}
impl Response {
pub fn from(response: reqwest::blocking::Response) -> Self {
let status = response.status();
let headers = response.headers().clone();
let body_result = response.text();
let mut body: Option<String> = None;
if let Ok(body_string) = body_result {
if !body_string.is_empty() {
body = Some(body_string);
}
}
Self {
body,
status,
headers,
}
}
}
#[derive(Debug)]
pub struct RequestOptions {
pub headers: HeaderMap,
pub timeout: Duration,
}