extern crate civet; extern crate conduit; use std::io::prelude::*; use std::io::{self, Cursor}; use std::sync::mpsc::channel; use civet::{Config, Server}; use conduit::{header, Body, RequestExt, Response}; macro_rules! http_write { ($dst:expr, $fmt:expr) => ( write!(&mut $dst, concat!($fmt, "\r\n"))? ); ($dst:expr, $fmt:expr, $($arg:tt)*) => ( write!(&mut $dst, concat!($fmt, "\r\n"), $($arg)*)? ) } fn main() { let _a = Server::start(Config::new(), handler); let (_tx, rx) = channel::<()>(); rx.recv().unwrap(); } fn handler(req: &mut dyn RequestExt) -> io::Result> { let mut res = Cursor::new(Vec::with_capacity(10000)); http_write!(res, ""); http_write!(res, "

{:?}

", req.http_version()); http_write!(res, "

Method: {:?}

", req.method()); http_write!(res, "

Scheme: {:?}

", req.scheme()); http_write!(res, "

Host: {:?}

", req.host()); http_write!(res, "

Path: {}

", req.path()); http_write!(res, "

Query String: {:?}

", req.query_string()); http_write!(res, "

Remote address: {}

", req.remote_addr()); http_write!(res, "

Content Length: {:?}

", req.content_length()); let mut body = String::new(); req.body().read_to_string(&mut body).unwrap(); http_write!(res, "

Input: {}", body); http_write!(res, "

Headers

"); let body: Body = Body::from_vec(res.into_inner()); Ok(Response::builder() .header(header::CONTENT_TYPE, "text/html") .body(body) .unwrap()) }