agate

Simple gemini server for static files
git clone https://github.com/mbrubeck/agate.git
Log | Files | Refs | README

commit a0c20258cb027df98c6995507eb25f20ec594fc4
parent bf439b4c526fa0d19b7128f5e2aca84b86271fd7
Author: Matt Brubeck <mbrubeck@limpet.net>
Date:   Sun, 17 May 2020 10:19:34 -0700

Working echo server

Diffstat:
MCargo.lock | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MCargo.toml | 1+
Msrc/main.rs | 15++++++++++-----
3 files changed, 105 insertions(+), 5 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -6,10 +6,20 @@ version = "1.0.0" dependencies = [ "async-std", "async-tls", + "env_logger", "rustls", ] [[package]] +name = "aho-corasick" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +dependencies = [ + "memchr", +] + +[[package]] name = "async-std" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -57,6 +67,17 @@ dependencies = [ ] [[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.8", +] + +[[package]] name = "autocfg" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -140,6 +161,19 @@ dependencies = [ ] [[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -266,6 +300,15 @@ dependencies = [ ] [[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] name = "iovec" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -467,6 +510,12 @@ dependencies = [ ] [[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] name = "quote" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -476,6 +525,24 @@ dependencies = [ ] [[package]] +name = "regex" +version = "1.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" + +[[package]] name = "ring" version = "0.16.13" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -543,6 +610,24 @@ dependencies = [ ] [[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -666,6 +751,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.8", +] + +[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -14,6 +14,7 @@ edition = "2018" async-tls = "0.7.0" async-std = "1.5" rustls = "0.17.0" +env_logger = "0.7.1" [profile.release] lto = true diff --git a/src/main.rs b/src/main.rs @@ -19,14 +19,19 @@ use { pub type Result<T=()> = std::result::Result<T, Box<dyn Error>>; async fn connection(acceptor: TlsAcceptor, stream: TcpStream) -> io::Result<()> { - let mut stream = acceptor.accept(stream).await?; - let mut body = Vec::new(); - stream.read_to_end(&mut body).await?; - stream.write_all(&body).await?; + 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(); + let certs = certs(&mut BufReader::new(File::open("tests/cert.pem")?)) .expect("Error reading certificate file"); let mut keys = rsa_private_keys(&mut BufReader::new(File::open("tests/key.rsa")?)) @@ -36,7 +41,7 @@ fn main() -> Result { config.set_single_cert(certs, keys.remove(0))?; let acceptor = TlsAcceptor::from(Arc::new(config)); - let addr = "127.0.0.1:1965"; + let addr = "localhost:1965"; task::block_on(async { let listener = TcpListener::bind(addr).await?;