From 1c5651e2f8ee80315cab493d4459a8f3be1b81e8 Mon Sep 17 00:00:00 2001 From: an-tao <20741618@qq.com> Date: Mon, 3 Sep 2018 14:04:26 +0800 Subject: [PATCH] Fix gzip bug --- lib/src/HttpServer.cc | 2 +- lib/src/Utilities.cc | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/HttpServer.cc b/lib/src/HttpServer.cc index 3f00599f..2a94fca0 100755 --- a/lib/src/HttpServer.cc +++ b/lib/src/HttpServer.cc @@ -171,7 +171,7 @@ void HttpServer::onRequest(const TcpConnectionPtr& conn, const HttpRequestPtr& r //use gzip LOG_TRACE<<"Use gzip to compress the body"; char *zbuf=new char[response->getBody().length()]; - size_t zlen; + size_t zlen=response->getBody().length(); if(gzcompress(response->getBody().data(), response->getBody().length(), zbuf,&zlen)>=0) diff --git a/lib/src/Utilities.cc b/lib/src/Utilities.cc index fd9aa390..961257d7 100755 --- a/lib/src/Utilities.cc +++ b/lib/src/Utilities.cc @@ -1,5 +1,6 @@ #include #include +#include #include #include namespace drogon{ @@ -245,7 +246,11 @@ int gzcompress(const char *data, const size_t ndata, c_stream.next_out = (Bytef *)zdata; c_stream.avail_out = *nzdata; while(c_stream.avail_in != 0 && c_stream.total_out < *nzdata) { - if(deflate(&c_stream, Z_NO_FLUSH) != Z_OK) return-1; + if(deflate(&c_stream, Z_NO_FLUSH) != Z_OK) + { + LOG_ERROR<<"compress err:"<