blob: 88752fbe1fc8601addffef7bc7079a60b0fac195 (
plain)
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
|
extern crate fastcgi;
extern crate http;
use std::io::Write;
use http::{Request, Response};
use http::request;
pub fn run<F, T>(handler: F)
where F: Fn(Request<()>) -> Response<T> + Send + Sync + 'static
{
fastcgi::run(move |mut req| {
// build request
let r = request::Builder::new()
.method("GET")
.body(())
.unwrap();
handler(r);
let params = req.params()
.map(|(k, v)| k + ": " + &v)
.collect::<Vec<String>>()
.join("\n");
write!(
&mut req.stdout(),
"Content-Type: text/plain\n\n{}",
params
)
.unwrap_or(());
});
}
trait From<T>: Sized {
fn from(_: T) -> Self;
}
impl From<fastcgi::Request> for http::request::Builder {
fn from(request: fastcgi::Request) -> Self {
let method = request.param("REQUEST_METHOD")
.unwrap_or("".to_owned());
let uri = format!(
"{}://{}{}",
request.param("REQUEST_SCHEME").unwrap_or("".to_owned()),
request.param("HTTP_HOST").unwrap_or("".to_owned()),
request.param("REQUEST_URI").unwrap_or("".to_owned()),
);
return http::request::Builder::new()
.method(&*method)
.uri(&uri)
// HTTP_* params become headers
}
}
|