diff options
| -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(()); +    });  } | 
