From ec50a315a3cfdbc7e5cc3387967eeca07c481b36 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 31 Dec 2020 17:02:45 -0800 Subject: [PATCH] Use concrete types for TlsStreams --- src/main.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1c0f2a3..cc99422 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use async_std::{ stream::StreamExt, task, }; -use async_tls::TlsAcceptor; +use async_tls::{TlsAcceptor, server::TlsStream}; use once_cell::sync::Lazy; use percent_encoding::{AsciiSet, CONTROLS, percent_decode_str, percent_encode}; use rustls::{ @@ -17,7 +17,6 @@ use std::{ ffi::OsStr, fs::File, io::BufReader, - marker::Unpin, path::Path, sync::Arc, }; @@ -127,9 +126,7 @@ fn acceptor() -> Result { } /// Return the URL requested by the client. -async fn parse_request( - stream: &mut R, -) -> std::result::Result { +async fn parse_request(stream: &mut TlsStream) -> std::result::Result { // Because requests are limited to 1024 bytes (plus 2 bytes for CRLF), we // can use a fixed-sized buffer on the stack, avoiding allocations and // copying, and stopping bad clients from making us use too much memory. @@ -177,7 +174,7 @@ async fn parse_request( } /// Send the client the file located at the requested URL. -async fn send_response(url: Url, stream: &mut W) -> Result { +async fn send_response(url: Url, stream: &mut TlsStream) -> Result { let mut path = std::path::PathBuf::from(&ARGS.content_dir); if let Some(segments) = url.path_segments() { for segment in segments { @@ -223,7 +220,7 @@ async fn send_response(url: Url, stream: &mut W) -> Result { Ok(()) } -async fn list_directory(stream: &mut W, path: &Path) -> Result { +async fn list_directory(stream: &mut TlsStream, path: &Path) -> Result { // https://url.spec.whatwg.org/#path-percent-encode-set const ENCODE_SET: AsciiSet = CONTROLS.add(b' ') .add(b'"').add(b'#').add(b'<').add(b'>') @@ -255,7 +252,7 @@ async fn list_directory(stream: &mut W, path: &Path) -> Result Ok(()) } -async fn send_header(stream: &mut W, status: u8, meta: &[&str]) -> Result { +async fn send_header(stream: &mut TlsStream, status: u8, meta: &[&str]) -> Result { use std::fmt::Write; let mut response = String::with_capacity(64); write!(response, "{} ", status)?; @@ -266,7 +263,7 @@ async fn send_header(stream: &mut W, status: u8, meta: &[&str] Ok(()) } -async fn send_text_gemini_header(stream: &mut W) -> Result { +async fn send_text_gemini_header(stream: &mut TlsStream) -> Result { if let Some(lang) = ARGS.language.as_deref() { send_header(stream, 20, &["text/gemini;lang=", lang]).await } else {