diff options
author | Teddy Wing | 2020-06-23 00:43:05 +0200 |
---|---|---|
committer | Teddy Wing | 2020-06-23 00:43:05 +0200 |
commit | c41a74411e155dc4e6caaec574786890470ef986 (patch) | |
tree | a925c21a910b5b40f7bf8fc0d59b14e6dbf3df44 /src | |
parent | 1f379b4cfa7c05f8f3429ddd666b1b9054020937 (diff) | |
download | fastcgi-conduit-c41a74411e155dc4e6caaec574786890470ef986.tar.bz2 |
Ideas for API
I want a wrapper for `fastcgi::run()` that uses `http::Request` and
`http::Response`.
Add a `lighttpd.conf` to test the FastCGI.
Print FastCGI params to give me an idea of what the request looks like.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 39 |
1 files changed, 33 insertions, 6 deletions
@@ -1,7 +1,34 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } +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(()); + }); } |