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
use std::collections::HashMap;
use httplib::Response;
pub trait Context {
fn get_response(&self) -> Response<String>;
fn set_body(&mut self, String);
}
pub struct BasicContext {
pub body: String,
pub params: HashMap<String, String>,
pub query_params: HashMap<String, String>
}
impl BasicContext {
pub fn new() -> BasicContext {
BasicContext {
body: "".to_owned(),
params: HashMap::new(),
query_params: HashMap::new()
}
}
}
impl Context for BasicContext {
fn get_response(&self) -> Response<String> {
let mut response = Response::builder();
response.body(self.body.clone()).unwrap()
}
fn set_body(&mut self, body: String) {
self.body = body;
}
}