diff options
Diffstat (limited to 'parrot/src/main.rs')
-rw-r--r-- | parrot/src/main.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/parrot/src/main.rs b/parrot/src/main.rs new file mode 100644 index 0000000..d3fe60f --- /dev/null +++ b/parrot/src/main.rs @@ -0,0 +1,33 @@ +use std::{ + env, + fs::File, + io::{BufWriter, Read, Write}, +}; + +fn main() { + println!("Content-Type: text/plain\n"); + + let mut bw = BufWriter::new(File::create("/tmp/parrot-debug").unwrap()); + + for (key, value) in env::vars() { + let log = format!("{key}: {value}\n"); + print!("{log}"); + bw.write_all(log.as_bytes()).unwrap(); + } + + let mut buf = vec![]; + std::io::stdin().read_to_end(&mut buf).unwrap(); + + match std::str::from_utf8(&buf) { + Err(_e) => { + let log = format!("\n(binary data; {} bytes)\n", buf.len()); + print!("{log}"); + bw.write_all(log.as_bytes()).unwrap(); + } + Ok(s) => { + let log = format!("\n{s}\n"); + print!("{log}"); + bw.write_all(log.as_bytes()).unwrap(); + } + } +} |