From bf09e83d53f2059e961939d6a323a8de57b017cd Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Sun, 17 May 2020 10:39:30 -0700 Subject: [PATCH] Minor changes --- src/main.rs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index d6a5619..8361759 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,17 +18,6 @@ use { pub type Result = std::result::Result>; -async fn connection(acceptor: TlsAcceptor, stream: TcpStream) -> io::Result<()> { - let stream = acceptor.accept(stream).await?; - let mut stream = async_std::io::BufReader::new(stream); - let mut body = String::new(); - stream.read_line(&mut body).await?; - let mut stream = stream.into_inner(); - stream.write_all(b"20 text/plain\r\n").await?; - stream.write_all(body.as_bytes()).await?; - Ok(()) -} - fn main() -> Result { env_logger::init(); @@ -60,3 +49,20 @@ fn main() -> Result { Ok(()) }) } + +async fn connection(acceptor: TlsAcceptor, stream: TcpStream) -> io::Result<()> { + let stream = acceptor.accept(stream).await?; + + let mut stream = async_std::io::BufReader::new(stream); + let mut body = String::new(); + stream.read_line(&mut body).await?; + eprintln!("Got request: {:?}", body); + + let mut stream = stream.into_inner(); + stream.write_all(b"20 text/plain\r\n").await?; + stream.write_all(b"=> ").await?; + stream.write_all(body.trim().as_bytes()).await?; + stream.write_all(b" Go to ").await?; + stream.write_all(body.as_bytes()).await?; + Ok(()) +}