1use std::collections::HashMap;
2use std::sync::Arc;
3
4pub struct HttpRequest {
5 pub method: String,
6 pub content: String,
7 pub content_type: String,
8 pub url: String,
9 pub parameters: HashMap<String, String>,
10 pub headers: HashMap<String, String>,
11}
12
13
14pub struct HttpResponse {
15 pub content: String,
16 pub content_type: String,
17 pub status: u16,
18 pub headers: HashMap<String, String>,
19}
20
21impl HttpResponse {
22 pub fn new(content: String) -> HttpResponse {
23 HttpResponse {
24 content,
25 content_type: "plain/text".to_string(),
26 status: 200,
27 headers: HashMap::from([("Access-Control-Allow-Origin".to_string(), "*".to_string())]),
28 }
29 }
30 pub fn new2(content: &str) -> HttpResponse {
31 HttpResponse {
32 content: content.to_string(),
33 content_type: "plain/text".to_string(),
34 status: 200,
35 headers: HashMap::new(),
36 }
37 }
38}
39
40
41pub type HttpHandler = Arc<dyn Fn(HttpRequest) -> HttpResponse + Send + Sync>;