#![feature(old_io)] extern crate "simple-cgi" as scgi; extern crate url; #[allow(unused_imports)] use scgi::{SCGIEnv, TcpSCGIServer, UnixSCGIServer, SCGIServer}; use std::old_io::net::tcp::TcpListener; use std::old_io::{IoResult, Stream}; fn process(w: &mut Stream, env: &SCGIEnv) -> IoResult<()> { try!(w.write_str("Status: 200 OK\r\n")); try!(w.write_str("Content-Type: text/html\r\n")); try!(w.write_str("Set-Cookie: rust=rulez\r\n")); try!(w.write_str("Set-Cookie: ssid=123\r\n")); try!(w.write_str("\r\n")); try!(w.write_str("")); try!(w.write_str("")); try!(w.write_str("Rust SCGI test server")); try!(w.write_str("")); try!(w.write_str("")); try!(w.write_str("

Headers

")); try!(w.write_str("")); for (k, v) in env.env.iter() { try!(w.write_str("")); } try!(w.write_str("
NameValue
")); try!(w.write_str(&**k)); try!(w.write_str("")); try!(w.write_str(&**v)); try!(w.write_str("
")); try!(w.write_str("

Query string

")); try!(w.write_str("")); if let Some(query) = env.query() { for (k, v) in query.iter() { try!(w.write_str("")); } } try!(w.write_str("
NameValue
")); try!(w.write_str(&**k)); try!(w.write_str("")); try!(w.write_str(&**v)); try!(w.write_str("
")); try!(w.write_str("

Cookies

")); try!(w.write_str("")); if let Some(cookies) = env.cookies() { for (k, v) in cookies.iter() { try!(w.write_str("")); } } try!(w.write_str("
NameValue
")); try!(w.write_str(&**k)); try!(w.write_str("")); try!(w.write_str(&**v)); try!(w.write_str("
")); try!(w.write_str("

Form

")); try!(w.write_str("


")); let content_length = env.content_length(); if content_length > 0 { try!(w.write_str("
"));
        let data = try!(w.read_exact(content_length));
        try!(w.write_all(&*data));
        try!(w.write_str("
")); } try!(w.write_str("")); Ok(()) } fn main() { let server = SCGIServer::new(TcpListener::bind("localhost:9000").unwrap()); //let server = UnixSCGIServer::new("/tmp/rust-scgi-server").unwrap(); server.run(process); }