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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::{io, slice, str, fmt};
use tokio_http2::http::{Request, Response, HttpProto};
use tokio_http2::StatusCode;
use rustc_serialize::json::*;
use rustc_serialize::base64::*;
pub fn route(req: Request) -> Response {
match req.path() {
"/admin/settings" => {
delete(req)
},
_ => Response::new().with_status(StatusCode::MethodNotAllowed),
}
}
fn delete(req: Request) -> Response {
let mut has_payload: bool = false;
match req.content_type() {
"application/json" => {
match req.payload() {
Some(payload) => {
let data = Json::from_str(str::from_utf8(payload).unwrap_or("{}"));
has_payload = true;
println!("{}", data.unwrap().pretty());
},
None => {},
}
},
"application/base64" => {
match req.payload() {
Some(payload) => {
let data = payload.from_base64();
has_payload = true;
println!("{:?}", data.unwrap());
},
None => {},
}
},
"application/x-www-form-urlencoded" => {
match req.payload() {
Some(payload) => {
has_payload = true;
},
None => {},
}
},
_ => {
match req.payload() {
Some(payload) => {
has_payload = true;
println!("{}", str::from_utf8(payload).unwrap_or(""));
},
None => {},
}
},
}
if has_payload {
Response::new()
.with_header("Server", "lsioHTTPS")
.with_header("Content-Length", "0")
.with_status(StatusCode::Ok)
} else {
Response::new()
.with_header("Server", "lsioHTTPS")
.with_header("Content-Length", "0")
.with_status(StatusCode::BadRequest)
}
}