diff options
| author | Teddy Wing | 2018-11-04 21:03:10 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-11-04 21:03:10 +0100 | 
| commit | 9b76995433d5dacf4a42be6d1920f981cd8014d6 (patch) | |
| tree | ce0a39de41dbdb2801f88cc89dae3fbfbb6cbe65 | |
| parent | 304ba6a5f4c4ddd179c43c29faac4d99bb874109 (diff) | |
| download | dome-key-web-9b76995433d5dacf4a42be6d1920f981cd8014d6.tar.bz2 | |
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.
| -rw-r--r-- | license-generator/src/main.rs | 23 | 
1 files changed, 22 insertions, 1 deletions
| 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(()); +    });  } | 
