From 6315dd85eee09251077990c195a6984091ce9084 Mon Sep 17 00:00:00 2001 From: antao Date: Mon, 3 Sep 2018 11:25:03 +0800 Subject: [PATCH] Update HttpServer --- lib/src/HttpServer.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/src/HttpServer.cc b/lib/src/HttpServer.cc index 0f4fe8ac..3f00599f 100755 --- a/lib/src/HttpServer.cc +++ b/lib/src/HttpServer.cc @@ -170,15 +170,23 @@ void HttpServer::onRequest(const TcpConnectionPtr& conn, const HttpRequestPtr& r { //use gzip LOG_TRACE<<"Use gzip to compress the body"; - char zbuf[response->getBody().length()]; + char *zbuf=new char[response->getBody().length()]; size_t zlen; if(gzcompress(response->getBody().data(), response->getBody().length(), zbuf,&zlen)>=0) { - response->setBody(std::string(zbuf,zlen)); - response->addHeader("Content-Encoding","gzip"); + if(zlen>0) + { + response->setBody(std::string(zbuf,zlen)); + response->addHeader("Content-Encoding","gzip"); + } + else + { + LOG_ERROR<<"gzip got 0 length result"; + } } + delete [] zbuf; } std::dynamic_pointer_cast(response)->appendToBuffer(&buf);