agate

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

commit c563f27b1a016eb5a5bf920cfd890215aece8d92
parent 33d39cc34b3feaf0a7139952d91bce200e262bba
Author: Matt Brubeck <mbrubeck@limpet.net>
Date:   Fri,  1 Jan 2021 20:05:07 -0800

Send close_notify before closing connection

Diffstat:
Msrc/main.rs | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -102,17 +102,19 @@ fn check_path(s: String) -> Result<String, String> { /// Handle a single client session (request + response). async fn handle_request(stream: TcpStream) -> Result { - // Perform handshake. - static TLS: Lazy<TlsAcceptor> = Lazy::new(|| acceptor().unwrap()); let stream = &mut TLS.accept(stream).await?; match parse_request(stream).await { - Ok(url) => send_response(url, stream).await, - Err((status, msg)) => send_header(stream, status, &[msg]).await, + Ok(url) => send_response(url, stream).await?, + Err((status, msg)) => send_header(stream, status, &[msg]).await?, } + stream.shutdown().await?; + Ok(()) } /// TLS configuration. +static TLS: Lazy<TlsAcceptor> = Lazy::new(|| acceptor().unwrap()); + fn acceptor() -> Result<TlsAcceptor> { let cert_file = File::open(&ARGS.cert_file)?; let certs = certs(&mut BufReader::new(cert_file)).or(Err("bad cert"))?;