From 3ef7b2751e40e75b0d631d447bf3d6bd3b01ecc0 Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Sat, 5 Dec 2020 13:39:29 -0500 Subject: [PATCH] Warn if a response is sent with a non-success code & a body --- src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index cbe2f4c..e12ab6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -428,7 +428,6 @@ impl ServerInner { async fn send_response(&self, response: Response, stream: &mut (impl AsyncWrite + Unpin + Send)) -> Result<()> { let use_complex_timeout = - response.is_success() && response.body.is_some() && response.meta != "text/plain" && response.meta != "text/gemini" && @@ -448,6 +447,15 @@ impl ServerInner { send_body_timeout = None; } + if !response.is_success() && response.body.is_some() { + warn!(concat!( + "Received a response with a body, but a status code of {} (!= 20). ", + " Responses should only have a body if their status code is 20. The body", + " will be sent, but this is likely to cause unexpected behavior."), + response.status, + ); + } + opt_timeout(send_general_timeout, async { // Send the header opt_timeout(send_header_timeout, send_response_header(&response, stream))