From 885a1f78a55eaa3918988777d90b3e0ca704c4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20L=C3=B6thberg?= Date: Fri, 30 Dec 2022 19:15:21 +0100 Subject: [PATCH] Make server buffer writes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #199. Signed-off-by: Johannes Löthberg --- src/server/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index 67af9f0..79164d4 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,7 +1,7 @@ //! Process HTTP connections on the server. use async_std::future::{timeout, Future, TimeoutError}; -use async_std::io::{self, Read, Write}; +use async_std::io::{self, Read, Write, BufWriter, WriteExt}; use http_types::headers::{CONNECTION, UPGRADE}; use http_types::upgrade::Connection; use http_types::{Request, Response, StatusCode}; @@ -159,7 +159,9 @@ where let mut encoder = Encoder::new(res, method); - let bytes_written = io::copy(&mut encoder, &mut self.io).await?; + let mut stream = BufWriter::new(&mut self.io); + let bytes_written = io::copy(&mut encoder, &mut stream).await?; + stream.flush().await?; log::trace!("wrote {} response bytes", bytes_written); let body_bytes_discarded = io::copy(&mut body, &mut io::sink()).await?;