mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
fix #109
This commit is contained in:
parent
76ea8dd560
commit
5ad4311fb0
1 changed files with 10 additions and 6 deletions
16
httplib.h
16
httplib.h
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue