From 3eec617189e19b4160432537702844e545e4b272 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 18 Oct 2021 19:41:18 +0200 Subject: httpsys: Added automatic translation of 200 OK -> 204 NO CONTENT for case where there is no body (upset some clients) --- zenhttp/httpsys.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'zenhttp/httpsys.cpp') diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp index f3568bbd1..cdf9e0a39 100644 --- a/zenhttp/httpsys.cpp +++ b/zenhttp/httpsys.cpp @@ -341,8 +341,6 @@ HttpMessageResponseRequest::~HttpMessageResponseRequest() void HttpMessageResponseRequest::InitializeForPayload(uint16_t ResponseCode, std::span BlobList) { - m_ResponseCode = ResponseCode; - const uint32_t ChunkCount = gsl::narrow(BlobList.size()); m_HttpDataChunks.reserve(ChunkCount); @@ -407,6 +405,16 @@ HttpMessageResponseRequest::InitializeForPayload(uint16_t ResponseCode, std::spa m_RemainingChunkCount = gsl::narrow(m_HttpDataChunks.size()); m_TotalDataSize = LocalDataSize; + + if (m_TotalDataSize == 0 && ResponseCode == 200) + { + // Some HTTP clients really don't like empty responses unless a 204 response is sent + m_ResponseCode = uint16_t(HttpResponseCode::NoContent); + } + else + { + m_ResponseCode = ResponseCode; + } } void -- cgit v1.2.3