Warn if a response is sent with a non-success code & a body

This commit is contained in:
Emi Tatsuo 2020-12-05 13:39:29 -05:00
parent b1d1fb7c0d
commit 3ef7b2751e
Signed by: Emi
GPG key ID: 68FAB2E2E6DFC98B

View file

@ -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))