Update HttpServer

This commit is contained in:
antao 2018-09-03 11:25:03 +08:00
parent 790867d1e3
commit 6315dd85ee
1 changed files with 11 additions and 3 deletions

View File

@ -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<HttpResponseImpl>(response)->appendToBuffer(&buf);