From 359c26b0bf8e728bf857dacacff70627c6ae5738 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Mon, 25 Jan 2021 14:04:48 +0100 Subject: [PATCH] Send back connection close header --- src/HttpResponse.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/HttpResponse.h b/src/HttpResponse.h index cf5732d..d91fe64 100644 --- a/src/HttpResponse.h +++ b/src/HttpResponse.h @@ -106,6 +106,16 @@ private: /* In some cases, such as when refusing huge data we want to close the connection when drained */ if (closeConnection) { + + /* HTTP 1.1 must send this back unless the client already sent it to us. + * It is a connection close when either of the two parties say so but the + * one party must tell the other one so. + * + * This check also serves to limit writing the header only once. */ + if ((httpResponseData->state & HttpResponseData::HTTP_CONNECTION_CLOSE) == 0) { + writeHeader("Connection", "close"); + } + httpResponseData->state |= HttpResponseData::HTTP_CONNECTION_CLOSE; }