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 | |
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.
-rw-r--r-- | examples/server.rs | 17 | ||||
-rw-r--r-- | lighttpd.conf | 19 | ||||
-rw-r--r-- | src/lib.rs | 39 |
3 files changed, 69 insertions, 6 deletions
diff --git a/examples/server.rs b/examples/server.rs new file mode 100644 index 0000000..f3a9c76 --- /dev/null +++ b/examples/server.rs @@ -0,0 +1,17 @@ +extern crate http; + +use http::{Response, StatusCode}; + +use fcgi_rs; + + +fn main() { + fcgi_rs::run(|req| { + let resp = Response::builder() + .status(StatusCode::OK) + .body(()) + .unwrap(); + + return resp; + }); +} diff --git a/lighttpd.conf b/lighttpd.conf new file mode 100644 index 0000000..20ca3ce --- /dev/null +++ b/lighttpd.conf @@ -0,0 +1,19 @@ +var.log_root = "/usr/local/var/log/lighttpd" +var.server_root = "." +server.document-root = server_root +server.port = 8080 +server.errorlog = log_root + "/error.log" + +server.modules += ( "mod_fastcgi" ) + +fastcgi.debug = 1 +fastcgi.server = ( + "/" => (( + "socket" => "./server.fcgi.socket", + "check-local" => "disable", + "bin-path" => var.CWD + "/target/debug/examples/server", + "max-procs" => 1 + )), +) + +include "/usr/local/etc/lighttpd/conf.d/mime.conf" @@ -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(()); + }); } |