From 9b76995433d5dacf4a42be6d1920f981cd8014d6 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 4 Nov 2018 21:03:10 +0100 Subject: Make a simple FastCGI echo server Building on the example from the 'fastcgi' crate: https://docs.rs/fastcgi/1.0.0/fastcgi/index.html prints all request parameters and the request `Stdin`. Post parameters are included in the stdin buffer. --- license-generator/src/main.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'license-generator/src') diff --git a/license-generator/src/main.rs b/license-generator/src/main.rs index e7a11a9..fab9eb1 100644 --- a/license-generator/src/main.rs +++ b/license-generator/src/main.rs @@ -1,3 +1,24 @@ +extern crate fastcgi; + +use std::io::{Read, Write}; + fn main() { - println!("Hello, world!"); + fastcgi::run(|mut req| { + write!(&mut req.stdout(), "Content-Type: text/plain\n\nHello, world!") + .unwrap_or(()); + + let mut params = String::new(); + for (key, val) in req.params() { + params.push_str(format!("{}: {}\n", key, val).as_str()); + } + + write!(&mut req.stdout(), "\n\n{}", params) + .unwrap_or(()); + + let mut stdin = String::new(); + req.stdin().read_to_string(&mut stdin).unwrap(); + + write!(&mut req.stdout(), "\n\nstdin: {}\n", stdin) + .unwrap_or(()); + }); } -- cgit v1.2.3