This commit is contained in:
yhirose 2018-11-22 20:50:54 -05:00
parent 76ea8dd560
commit 5ad4311fb0

View file

@ -1643,7 +1643,16 @@ inline void Server::write_response(Stream& strm, bool last_connection, const Req
res.set_header("Connection", "Keep-Alive");
}
if (!res.body.empty()) {
if (res.body.empty()) {
if (!res.has_header("Content-Length")) {
if (res.streamcb) {
// Streamed response
res.set_header("Transfer-Encoding", "chunked");
} else {
res.set_header("Content-Length", "0");
}
}
} else {
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
// TODO: 'Accpet-Encoding' has gzip, not gzip;q=0
const auto& encodings = req.get_header_value("Accept-Encoding");
@ -1660,11 +1669,6 @@ inline void Server::write_response(Stream& strm, bool last_connection, const Req
auto length = std::to_string(res.body.size());
res.set_header("Content-Length", length.c_str());
} else if (res.streamcb) {
// Streamed response
bool chunked_response = !res.has_header("Content-Length");
if (chunked_response)
res.set_header("Transfer-Encoding", "chunked");
}
detail::write_headers(strm, res);