aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0da0f58..5d26a98 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -241,10 +241,33 @@ impl<'a> conduit::RequestExt for FastCgiRequest<'a> {
}
-struct Server;
+pub struct Server;
impl Server {
pub fn start<H: Handler + 'static + Sync>(handler: H) -> io::Result<Server> {
+ fastcgi::run(move |mut raw_request| {
+ let mut request = FastCgiRequest::new(&mut raw_request).unwrap();
+ let response = handler.call(&mut request);
+
+ let mut stdout = raw_request.stdout();
+
+ let (head, body) = response.unwrap().into_parts();
+
+ for (name, value) in head.headers.iter() {
+ write!(&mut stdout, "{}: ", name).unwrap();
+ stdout.write(value.as_bytes()).unwrap();
+ stdout.write(b"\r\n").unwrap();
+ }
+
+ stdout.write(b"\r\n").unwrap();
+
+ match body {
+ conduit::Body::Static(slice) => stdout.write(slice).map(|_| ()).unwrap(),
+ conduit::Body::Owned(vec) => stdout.write(&vec).map(|_| ()).unwrap(),
+ conduit::Body::File(file) => (),
+ };
+ });
+
Ok(Server{})
}
}