From 1caa728cb46db4d334204b652a46c27f2fc68ac4 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Sat, 1 Jul 2023 12:19:44 +0200 Subject: Cleaning up. Starting with response-function. --- src/cgidebug.rs | 81 --------------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 src/cgidebug.rs (limited to 'src/cgidebug.rs') diff --git a/src/cgidebug.rs b/src/cgidebug.rs deleted file mode 100644 index afdc7ca..0000000 --- a/src/cgidebug.rs +++ /dev/null @@ -1,81 +0,0 @@ -use std::io::Write; -use std::env; -use std::collections::btree_map::BTreeMap; - -fn write_stderr( msg : String ) { - let mut stderr = std::io::stderr(); - write!(&mut stderr, "{}", msg).unwrap(); -} - -fn write_stderr_s( msg : &str ) { - write_stderr( msg.to_string() ); -} - -fn write_stdout( msg : String ) { - let mut stdout = std::io::stdout(); - write!(&mut stdout, "{}", msg).unwrap(); -} - -fn write_stdout_s( msg : &str ) { - write_stdout( msg.to_string() ); -} - -fn html_escape( msg : String ) -> String { - let mut copy : String = String::with_capacity( msg.len() ); - - for thechar in msg.chars() { - if thechar == '&' { - copy.push_str( "&" ); - } else if thechar == '<' { - copy.push_str( "<" ); - } else if thechar == '>' { - copy.push_str( ">" ); - } else if thechar == '\"' { - copy.push_str( """ ); - } else { - copy.push( thechar ); - } - } - - return copy; -} - -fn main() { - write_stdout_s( "Status: 301 Moved Permanently\n" ); - write_stdout_s( "Location: https://www.vg.no\n" ); - write_stdout_s( "Content-type: text/html\n" ); - write_stdout_s( "\n" ); - write_stdout_s( "\n" ); - write_stdout_s( " \n" ); - write_stdout_s( " Rust CGI Test\n" ); - write_stdout_s( " \n" ); - write_stdout_s( " \n" ); - write_stdout_s( " \n" ); - write_stdout_s( "

Environment

\n" ); - write_stdout_s( " \n" ); - write_stdout_s( " \n" ); - - // copy environment into a BTreeMap which is sorted - let mut sortedmap : BTreeMap = BTreeMap::new(); - for (key, value) in env::vars() { - sortedmap.insert( key, value ); - } - - // output environment into HTML table - for (key, value) in sortedmap { - write_stdout( - format!( - " \n", - html_escape( key ), - html_escape( value ) - ) - ); - } - write_stdout_s( "
KeyValue
{}{}
\n" ); - write_stdout_s( " \n" ); - write_stdout_s( "\n" ); -} -- cgit v1.2.3