diff --git a/lib/src/HttpServer.cc b/lib/src/HttpServer.cc index e96a9d40..7dabc253 100755 --- a/lib/src/HttpServer.cc +++ b/lib/src/HttpServer.cc @@ -175,10 +175,19 @@ void HttpServer::onRequest(const TcpConnectionPtr &conn, const HttpRequestPtr &r return; response->setCloseConnection(_close); //if the request method is HEAD,remove the body of response(rfc2616-9.4) - if (_isHeadMethod) - response->setBody(std::string()); - auto &sendfileName = std::dynamic_pointer_cast(response)->sendfileName(); auto newResp = response; + if (_isHeadMethod) + { + if (newResp->expiredTime() >= 0) + { + //Cached response,make a copy + newResp = std::make_shared(*std::dynamic_pointer_cast(response)); + } + newResp->setBody(std::string()); + } + + auto &sendfileName = std::dynamic_pointer_cast(newResp)->sendfileName(); + if (HttpAppFramework::instance().useGzip() && sendfileName.empty() && req->getHeader("Accept-Encoding").find("gzip") != std::string::npos &&