From a613320c5f69089feba14ef36de58bdc21dd7e0b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 28 Jun 2020 18:22:18 +0200 Subject: Server: Working `start()` implementation Got a draft version of the server working. Change the example to use the new Conduit server. Got a working HTML fragment response. Need to handle `conduit::Body::File` as well as unwrapped errors. --- examples/server.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/server.rs b/examples/server.rs index 7460f56..864c105 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -1,27 +1,26 @@ +extern crate conduit; extern crate http; +extern crate fastcgi_conduit; use std::fs::OpenOptions; use std::io::prelude::*; +use std::io; -use http::{Response, StatusCode}; +use conduit::{Body, RequestExt, Response}; +use conduit::header; -use fcgi; +use fastcgi_conduit::Server; fn main() { - fcgi::run(move |req| { - let mut file = OpenOptions::new() - .write(true) - .append(true) - .open("/tmp/fcgi-log.txt") - .unwrap(); - write!(file, "ยป {:?}\n", req).unwrap(); - - let resp = Response::builder() - .status(StatusCode::OK) - .body(()) - .unwrap(); + Server::start(handler); +} - return resp; - }); +fn handler(req: &mut dyn RequestExt) -> io::Result> { + Ok( + Response::builder() + .header(header::CONTENT_TYPE, "text/html") + .body(Body::from_static(b"

Test

")) + .unwrap() + ) } -- cgit v1.2.3